我正在尝试在新进程上打开cmd.exe并传递一些代码以编程方式弹出设备;但是当我试图做到这一点时,我得到的是:
“错误#2044:未处理的IOErrorEvent:。text =错误#3218:将数据写入NativeProcess.standardInput时出错。”
这是我的代码:
private var NP:NativeProcess = new NativeProcess();
private function EjectDevice():void
{
var RunDLL:File = new File("C:\\Windows\\System32\\cmd.exe");
var NPI:NativeProcessStartupInfo = new NativeProcessStartupInfo();
NPI.executable = RunDLL;
NP.start(NPI);
NP.addEventListener(Event.STANDARD_OUTPUT_CLOSE, CatchOutput, false, 0, true);
NP.standardInput.writeUTFBytes("start C:\\Windows\\System32\\rundll32.exe shell32.dll,Control_RunDLL hotplug.dll");
NP.closeInput();
}
我也尝试过writeUTF而不是writeUTFBytes,但我仍然得到错误。有没有人知道我做错了什么?。
感谢您的时间:) 爱德华。
答案 0 :(得分:2)
也许cmd.exe不像普通进程那样处理standardInput。
您可以尝试将要执行的内容作为参数传递给cmd进程,而不是写入标准输入
我认为
cmd.exe /C "start C:\Windows\System32\rundll32.exe shell32.dll,Control_RunDLL hotplug.dll"
是将某些内容作为参数传递给cmd以立即执行的格式。
此站点有一个使用字符串向量传递过程参数的示例:
http://blogs.adobe.com/cantrell/archives/2009/11/demo_of_nativeprocess_apis.html
答案 1 :(得分:2)
尝试不使用最后一行“NP.closeInput();”
另见:
http://help.adobe.com/en_US/as3/dev/WSb2ba3b1aad8a27b060d22f991220f00ad8a-8000.html
答案 2 :(得分:1)
我同意abudaan,你不应该closeInput()
。
另外,建议您在writeUTFBytes()调用结束时添加换行符,例如:
NP.standardInput.writeUTFBytes("start C:\\Windows\\System32\\rundll32.exe shell32.dll,Control_RunDLL hotplug.dll **\n**");
最后,我建议你听NativeProcess上的其他事件,我使用这样的代码块:
NP.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onStdOutData);
NP.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onStdErrData);
NP.addEventListener(Event.STANDARD_OUTPUT_CLOSE, onStdOutClose);
NP.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, onStdInputProgress);
NP.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
NP.addEventListener(IOErrorEvent.STANDARD_INPUT_IO_ERROR, onIOError);
NP.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
使用正常的事件处理函数,至少跟踪它们收到的内容。
祝您好运 - 我只花了几个小时使用cmd.exe改进NativeProcess - 它很繁琐。但我最终到了那里,你也会。