将从脚本启动的shell命令的输出发送到日志文件

我有一个php页面创建一个shell脚本,在创建它之后启动相同的php页面,我有一个 我希望将进程发送到日志的许多命令,这些日志在其他人实际工作时不起作用.... </ p>

 &lt; php 
$ scriptfile = script.sh ;
$ logfile = process.log;
$ imgfile = image.ppm;

//这个有效,它将输出发送到日志文件
$ cmd =“Scripts / convert.sh文件。 doc&gt; $ logfile \
“;
file_put_contents($ scriptfile,$ cmd,FILE_APPEND | LOCK_EX);

//这个不起作用,它不会将输出发送到日志文件并停止 process
$ cmd =“&amp;&amp; for i in $(seq --format =%003.f 0 $(($(ls -1 | wc -l)-1)));做echo做OCR on page \ $ i; tesseract $ imgfile - \ $ i.ppm $ imgfile - \ $ i -l eng; done&gt;&gt; $ logfile“;
file_put_contents($ scriptfile,$ cmd,FILE_APPEND | LOCK_EX);
\ n $ cmd =“/ bin / sh $ scriptfile&gt; / dev / null 2&gt;&amp; 1&amp;”;
shell_exec($ cmd);
?&gt;
</ code> </ pre>

我尝试过来自shell的not working命令,它确实将输出发送到日志文件,这样:</ p>

  for i in $(seq  --format =%003.f 0 $(($(ls -1 |  wc -l)-1))); 在页面$ i上做回声做OCR;  tesseract image- $ i.ppm image  -  \ $ i -l eng; 完成&gt;&gt;  process.log 
</ code> </ pre>

或者这样:</ p>

  for i in $(seq --format =%003  .f 0 $(($(ls -1 | wc -l)-1))); 在页面$ i&gt;&gt;上做回声做OCR  process.log;  tesseract image- $ i.ppm image  -  \ $ i -l eng; 完成
</ code> </ pre>

这里有shell脚本在php创建后的样子:</ p>

 #  !  /bin/sh
Scripts/convert.sh file.doc&gt;&gt; process.log \
&amp;&amp; for $ in $(seq --format =%003.f 0 $(($(ls -1 | wc -l)-1))); 在页面$ i上做回声做OCR; tesseract image-000.ppm image- $ i -l eng; 完成&gt;&gt; process.log
</ code> </ pre>

所以我的问题是,可能出现了什么问题,我已经尝试了许多不同的事情,但不幸的是没有成功,任何帮助或建议都会非常 欢迎! 谢谢你们!</ p>
</ div>

展开原文

原文

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 \\
";
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!!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问