Detecting Exceptions from the target of Start-Process

Topics: Developer Forum, Project Management Forum, User Forum
Apr 26, 2008 at 9:32 PM
I have a .NET console application that I am calling with the following command:
start-process -path "myutil.exe" -waittimeout -1 -arguments "/arg1:hello /arg2:world"

I need to be able to tell if the application throws an unhandled exception because I would be treating that case as a terminating error and would need the script to stop running. I thought that by using the -ErrorVariable parameter I would be able to capture any exceptions that may have generated from the console application but that is not what happens. -ErrorVariable doesn't return anything. Is there a way to accomplish this?

Thanks, Paul
Apr 28, 2008 at 2:58 PM

paulkoanui wrote:
I have a .NET console application that I am calling with the following command:
start-process -path "myutil.exe" -waittimeout -1 -arguments "/arg1:hello /arg2:world"

I need to be able to tell if the application throws an unhandled exception because I would be treating that case as a terminating error and would need the script to stop running. I thought that by using the -ErrorVariable parameter I would be able to capture any exceptions that may have generated from the console application but that is not what happens. -ErrorVariable doesn't return anything. Is there a way to accomplish this?

Thanks, Paul


I downloaded the source and checked out the Start-Process command. Since the cmdlet returns an array of Process classes I can inspect the ExitCode property to see if my app ran properly in case anyone else was wondering.
Coordinator
Apr 29, 2008 at 5:30 AM
Yep, that would be the way to go. AFAICT the Process class doesn't provide info on unhandled exceptions. Although you could probably look at what the adplus.vbs script does in the Debugging Tools for Windows if you really want to hook a process and be notified if it crashes.