问题
from another program (metatrader) I start a ps-script to download some emails:
shl = ShellExecuteW(0,0,"powershell.exe", "-file x.ps1","..\\path\\to\\scripts",SW_SHOW);
After a couple of weeks without any problem(!) I saw all of a sudden some red error code in the console - but it was closed too fast the return code (shl) signals no error: shl <=32.
Now I tried to start ShellExecuteW(..) with
shl = ShellExecuteW(0,0,"powershell.exe","..","..",SW_SHOWNOACTIVATE);
# SW_SHOWNOACTIVATE = 4
# 4: Displays a window in its most recent size and position. The active window remains active.
But again the console disappears :(
1) What do I have to enter so that the console stays open - for me to close 1t manually?
2) How do I force ShellExecuteW(..) to add the error-messages to an error file?
Thanks and a nice weekend,
Gooly
PS: After I re-started the program with ShellExecuteW(..) it runs again without any error?
回答1:
I think the problem is not ShellExecute, but how Powershell is invoked.
Try this:
shl = ShellExecuteW(0,0,"powershell.exe", "-noexit -file x.ps1","..\\path\\to\\scripts",SW_SHOW);
回答2:
Just for the record, You could have kept it open by adding read-host
at the end of your Script.
You can Log error messages by using transcripts (start-transcript
/ stop-transcript
) or just add error handling to your Script (try catch then log manually).
Regards
来源:https://stackoverflow.com/questions/26437529/how-to-keep-the-window-open-shellexecutew0-0-powershell-exe-sw-sh