我有一個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