Context: Oracle Enterprise Manager has a feature to “execute host command.” If into that feature I enter “dir c:\temp” then the output window echos the command and then shows a directory listing. If into that feature I enter “powershell dir c:\temp” the output window shows only the echo’d command. No directory listing. If on the target machine I enter those two commands in both cases I get the echo’d command followed by a directory listing.
I hypothesize that what I see in the cmd.exe window on the client blends two stdout streams: one from the cmd.exe itself and one from the invoked process (powershell dir c:\temp). The Oracle thing seems to recognize only the cmd.exe’s stdout.
Is there some way I can force the stdout from the invoked process to be in the cmd.exe’s stdout stream so that Oracle will recognize it and the thing I am trying to build will work?
I don’t think you can directly pipe the output from one program back into STDOUT of a parent cmd.exe – assuming that is what Oracle is doing at some level.
That being said, you could try something clever like the following:
Basically this is capturing the output from PowerShell, placing it in a temporary file, then dumping that file back onto STDOUT in cmd.exe. A nice touch would be cleaning up the temp file with a
& DEL %TEMP%\a.txton the end of the command.You will probably need to toy around with the command line to account for any quirks in how Oracle is passing things along – my guess is that it is invoking
cmd.exe /cdirectly so you can probably leave that part off.