我使用popenRWE從http://www.jukie.net/bart/blog/popenRWE,使下面C++ popen方法來運行PHP
int pipes[3];
int pid;
const char *const args[] = {
"php ",
NULL
};
pid = popenRWE(pipes, args[0], args);
char *cmd = "<?php echo 'hello world';?> ";
cout << "write: " << write(pipes[0], cmd, strlen(cmd)) << endl;
cout << "err: " << errno << endl;
char res[100];
cout << "read: " << read(pipes[1], res, 100) << endl;
cout << "result: " << res << endl;
劇本時,我使用cat
命令,它的工作原理,其輸入是輸出中(這是貓做什麼),但使用php
讀取爲空。我已確認已安裝了PHP和我的道路上通過直接在控制檯上運行
echo "<?php echo 'hello world';?>" | php
,並得到了輸出。有人可以請建議或幫助此代碼?提前致謝。
不'popenRWE'返回一個有效ID(即不是一個錯誤)?在'$ PATH'中是'php'嗎? –