Flex3 / Air 2: NativeProcess does not accept standard input (error # 2044 and # 3218)

I am trying to open cmd.exe in a new process and pass some code to programmatically retrieve the device; but when trying to do this all I get is:

"Error # 2044: Unhandled IOErrorEvent :. text = Error # 3218: Error writing data to NativeProcess.standardInput."

Here is my code:

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(); } 

I also tried with writeUTF instead of writeUTFBytes, but I still get the error. Does anyone have an idea of ​​what I'm doing wrong?

Thanks for your time :) Edward.

+4
source share
3 answers

Maybe cmd.exe does not handle standardInput like a normal process.

You can try to pass what you want to execute as parameters for the cmd process, instead of writing to standard input

I think,

 cmd.exe /C "start C:\Windows\System32\rundll32.exe shell32.dll,Control_RunDLL hotplug.dll" 

is a format for passing something as a parameter to cmd for immediate execution.

This site provides an example of passing process parameters using a vector string:

http://blogs.adobe.com/cantrell/archives/2009/11/demo_of_nativeprocess_apis.html

+2
source

Try this without the last line "NP.closeInput ();"

See also:

http://help.adobe.com/en_US/as3/dev/WSb2ba3b1aad8a27b060d22f991220f00ad8a-8000.html

+2
source

I agree with abudaan, you do not need closeInput() .

Also, suggest adding a line break at the end of the writeUTFBytes () call, for example:

 NP.standardInput.writeUTFBytes("start C:\\Windows\\System32\\rundll32.exe shell32.dll,Control_RunDLL hotplug.dll **\n**"); 

Finally, I recommend that you listen to other events in NativeProcess, I use a block of code like this:

 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); 

with normal event handler functions that at least keep track of what they get.

Good luck. I spent several hours developing NativeProcess with cmd.exe - this is vague. But I got there at the end, and so did you.

+1
source

Source: https://habr.com/ru/post/1308729/


All Articles