0

OK so im trying to get exec() to execute a script that works fine from idle.

If I try a simple script it works fine, such as:

hello = "hello"
world = "world"
print hello + " " + world

But the script I actually want to run wont work and I can only assume its because of the module import, the code is as follows:

import serial
port = serial.Serial('/dev/ttyAMA0', baudrate=19200, bytesize=8, parity=serial.PARITY_NONE, stopbits=1, timeout=5)
port.open

port.write("\x02\x00\x00\x00\x00\x02")

My PHP code is:

 <?php

   $result = exec('python python.py');#This works fine

   echo $result

   ?>

   <?php

   $result1 = exec('python proOn.py');# This wont work

   echo $result1

   ?>
Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
speks121
  • 11
  • 1
  • 2

1 Answers1

0

Try this:

<?php 

$command = escapeshellcmd('proOn.py');
$result1 = shell_exec($command);
echo $result1;

?>

refer this.

Community
  • 1
  • 1
Van Tr
  • 5,889
  • 2
  • 20
  • 44