我有一个PHP脚本,它创建了一个shell脚本,它在从同一个php文件中运行后运行,shell脚本生成一个注册表文件,脚本之后我需要读取它执行,再次从相同的PHP。 php读取文件,但是我认为它在文件被填充或创建之前就完成了,如果我再回到浏览器并再次执行php,那么textarea上就有内容。我试图解决它添加睡眠(),退出()函数和一些其他策略,但没有成功。下面是一些我尝试过的事情:PHP执行脚本后读取日志内容
// Creation of the shell script: Corpus alignment target to origin
......
$cmd = "cwb-align-encode -r $REGDIR -D $CORPUSLOCATION$corpusname/$corpusname"._."$lang_tg.align\n\n";
file_put_contents($scriptfile, $cmd, FILE_APPEND | LOCK_EX);
// Run the corpus indexation script
$cmd = "/bin/bash $scriptfile > /dev/null 2>&1 &";
shell_exec($cmd);
来自同一个PHP读取注册表文件:
// 1st try: no content at the textarea
echo "<textarea id='txtArea'>".htmlspecialchars(file_get_contents($REGDIR.$corpusname))."</textarea>";
// 2nd try: no content at the textarea
echo "<textarea id='txtArea'>".sleep(10); htmlspecialchars(file_get_contents($REGDIR.$corpusname))."</textarea>";
// 3rd try: no content at the textarea
echo "<textarea id='txtArea'>".exit(); htmlspecialchars(file_get_contents($REGDIR.$corpusname))."</textarea>";
// 4th try: no content at the textarea
echo "<textarea id='txtArea'>".if(filesize($REGDIR.$corpusname) != 0) { echo htmlspecialchars(file_get_contents($REGDIR.$corpusname)); } else { exit(0); sleep(10); htmlspecialchars(file_get_contents($REGDIR.$corpusname)); }."</textarea>";
是的,就这么简单取出'>的/ dev/null的2 >&1&'从shell脚本执行行。非常感谢。 –
np,很高兴它的工作! – Jeffrey