当前位置: 动力学知识库 > 问答 > 编程问答 >

php - send output of a shell command launched from script to a log file

问题描述:

I have a php page that creates a shell script that the same php page starts after creating it, inside I have one of many commands that I want to send the process to a log that does not work while others actually work....

<php

$scriptfile = script.sh;

$logfile = process.log;

$imgfile = image.ppm;

//this one works, it sends the output to the log file

$cmd ="Scripts/convert.sh file.doc > $logfile \\\n";

file_put_contents($scriptfile, $cmd, FILE_APPEND | LOCK_EX);

//this one does not work, it does not send the output to the log file and stops the process

$cmd = "&& for i in $(seq --format=%003.f 0 $(( $(ls -1 | wc -l) -1 )) ); do echo doing OCR on page \$i; tesseract $imgfile-\$i.ppm $imgfile-\$i -l eng; done >> $logfile";

file_put_contents($scriptfile, $cmd, FILE_APPEND | LOCK_EX);

$cmd = "/bin/sh $scriptfile > /dev/null 2>&1 &";

shell_exec($cmd);

?>

I have tried the not working command from the shell and it does send the output to the log file, either this way:

for i in $(seq --format=%003.f 0 $(( $(ls -1 | wc -l) -1 )) ); do echo doing OCR on page $i; tesseract image-$i.ppm image-\$i -l eng; done >> process.log

or this way:

for i in $(seq --format=%003.f 0 $(( $(ls -1 | wc -l) -1 )) ); do echo doing OCR on page $i >> process.log; tesseract image-$i.ppm image-\$i -l eng; done

And here you have the way the shell script looks like after being created by php:

#! /bin/sh

Scripts/convert.sh file.doc >> process.log \

&& for i in $(seq --format=%003.f 0 $(( $(ls -1 | wc -l) -1 )) ); do echo doing OCR on page $i; tesseract image-000.ppm image-$i -l eng; done >> process.log

So my question is, what can be wrong, I've tried many different things already but no success unfortunately, any help or advice will be very welcomed!! thanks from now!!

分享给朋友:
您可能感兴趣的文章:
随机阅读: