2

I'm trying to run python script via laravel using symfony process but when i run it I get this error: 'Python' is not recognized as an internal or external command, operable program or batch file. I tried to run the python script with cmd and it run and return the result

my laravel code is this:

`

$text="I luv my <3 iphone & you're awsm apple. DisplayIsAwesome, sooo happppppy 🙂 http://www.apple.com";
$process=new Process("Python C:\Users\Bcc\PycharmProjects\twitter-data\Car.py \"{$text}\"");
$process->run();
if (!$process->isSuccessful()){
            throw new ProcessFailedException($process);
}
var_dump($process->getOutput());
die();

` I run this command on cmd: Python C:\Users\Bcc\PycharmProjects\twitter-data\Car.py "I luv my <3 iphone & you're awsm apple. DisplayIsAwesome, sooo happppppy 🙂 http://www.apple.com"

EDIT: Problem Solved.I move python script to controllers folder and use shell_exec ,so just replace that code with this

    $text="I luv my &lt;3 iphone &amp; you're awsm apple. DisplayIsAwesome, sooo happppppy 🙂 http://www.apple.com";
    $result = shell_exec("python ". app_path()."\Http\Controllers\Car.py " . escapeshellarg($text));

    var_dump($result);
    die();
17
  • If you run the command manually over the command line, what happens? Commented Apr 11, 2018 at 8:06
  • 1
    it run and give me the result of the script Commented Apr 11, 2018 at 8:08
  • How are you running Laravel? Is it through a virtual machine such as Homestead (vagrant)? Commented Apr 11, 2018 at 8:14
  • no I run it on my localhost on port 8000 using php storm terminal Commented Apr 11, 2018 at 8:28
  • Can you post the command you're executing to run the above code? Commented Apr 11, 2018 at 8:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.