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

exec() with php command does not return any value

问题描述:

What actually i want to do is to get contents from the winword file in my web page.

for this purpose i used the exec() method, i also tried the following code:

$pCom = new COM("WScript.Shell");

$pShell = $pCom->exec("Notepad.exe");

$sStdOut = $pShell->StdOut->ReadAll; # Standard output

$sStdErr = $pShell->StdErr->ReadAll; # Error

echo($sStdOut);

the above code through an Exception that:

 Fatal error: Class 'COM' not found in D:\xampp\htdocs\test\tests\Notepad.php on line 9

I have no idea what to do and how to do this?

网友答案:

You have two issues with your approach:

  1. a text editor does not output text written in it when closing the editor. So why would you expect to receive the text when firing the editor by means of an exec() call?

  2. you miss understood how the exec() command actually works, I assume you did not really read the documentation of the exec() function which clearly states that the return value of an executed command is the last line of its output. That is not what you want.

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