I have to design a interface using PHP for a software written in python. Currently this software is used from command line by passing input, mostly the input is a text file. There are series of steps and for every step a python script is called. Every step takes a text file as input and an generates an output text file in the folder decided by the user. I am using system()
of php but I can't see the output but when I use the same command from command line it generates the output. Example of command :
python /software/qiime-1.4.0-release/bin/check_id_map.py -m /home/qiime/sample/Fasting_Map.txt -o /home/qiime/sample/mapping_output -v
Asked
Active
Viewed 636 times
2

El Developer
- 3,345
- 1
- 21
- 40

user1564657
- 97
- 2
- 5
-
Can you show the code you're using to call `system()`? – David Robinson Jul 31 '12 at 04:35
3 Answers
2
If you are not on windows, have you tried adding 2>&1
(redirect stderr to stdout) to the end of the command?
$output = system("python /software/qiime-1.4.0-release/bin/check_id_map.py -m /home/qiime/sample/Fasting_Map.txt -o /home/qiime/sample/mapping_output -v 2>&1", $exitcode);
Found from http://www.php.net/manual/en/function.system.php#108713
Also the doc says that it
Returns the last line of the command output on success, and FALSE on failure.
So if you are trying to get multiple lines, you may need to redirect it to a file and read that in.

justderb
- 2,835
- 1
- 25
- 38
-
Thank you very much for your time. I used the above trick and in this way I am getting something on the browser unlike before. But I am getting an error like this : Traceback (most recent call last): File "/software/qiime-1.4.0-release/bin/check_id_map.py", line 15, in from qiime.util import parse_command_line_parameters, get_options_lookup ImportError: No module named qiime.util – user1564657 Aug 05 '12 at 02:18
-
The code I am using is : $command='/software/python-2.7.1-release/bin/python /software/qiime-1.4.0-release/bin/check_id_map.py -m /home/qiime/sample/Fasting_Map.txt -o /home/qiime/sample/mapping_output -v 2>&1'; echo '
'; $last_line = system($command); echo $last_line
– user1564657 Aug 05 '12 at 02:21 -
The coomand I am using works on the command line but not when I am using via PHP's system() function – user1564657 Aug 05 '12 at 02:22
-
1I just fixed the problem. I needed to set the environment variable of php same as the environment variable of the linux terminal using PHP's putenv() function. – user1564657 Aug 05 '12 at 21:53
-
Hello user1564657, I am facing the same issue. Can you explain how did y set it? Thanks – ABA Jun 10 '14 at 18:45
-
@IGORALVES I believe they used: http://www.php.net//manual/en/function.putenv.php – justderb Jun 10 '14 at 20:55
-
Hi justderb Thanks for your take your time to reply. Yes they used putenv() but I dont know how they did that. How to use this function. Do you have any idea? The documentation on php manual is not clear for me. Thanks – ABA Jun 11 '14 at 13:44
-
Looks like they simply did `env` in the console, then copypasta'd the output into `putenv()`. That way their php system call mirrors their environment shell. But really, I think you only need to put the `PATH` environment variable into `putenv()`. (I don't think this is the right solution - but if it works for you, all the better!) – justderb Jun 11 '14 at 18:13
2
try this
$script = 'software/qiime-1.4.0-release/bin/check_id_map.py -m /home/qiime/sample/Fasting_Map.txt -o /home/qiime/sample/mapping_output -v';
$a = exec($script);

Rakesh
- 81,458
- 17
- 76
- 113
0
instead of system()
try surrounding the code in `ticks`...
It has a similar functionality but behaves a little differently in the way it returns the output..

Dean Rather
- 31,756
- 15
- 66
- 72