StartProcess Mystery #4141
Replies: 4 comments 1 reply
-
Hey @CharliePoole nothing has changed in You can prove this by executing // test-startprocess-notepad.cake
var exitCode = StartProcess("notepad.exe");
Information("I don't see this until I close notepad");
Information("notepad exit code: {0}", exitCode); I suspect that something changed with the executable that you are calling. It's likely that the executable is behaving like a bootstrapper, in the sense that it's launching another executable, and then finishes its execution. e.g. You call If that's the case, you'd need to find out what's the end process that needs to be executed, and call that instead (skipping this "launcher" app). ps: If you want, you can be more explicit about waiting for the process to end, but I'd expect you'll end up with the same result, unless you call the final app you want to run: var exitCode = -1;
using (var process = StartAndReturnProcess("notepad.exe"))
{
process.WaitForExit();
exitCode = process.GetExitCode();
}
Information("Exit code: {0}", exitCode);
// ... |
Beta Was this translation helpful? Give feedback.
-
@augustoproiete Thanks for your response. In fact, I did try the alternative you suggest, with the same result. I have concluded that there is some race condition in my application, so that the main process is terminating before all the work (done in a child process) has completed. However, I am only working on the Cake script, so something I have done there is exposing the race condition, which was not visible before. IOW, still some remote chance of a Cake bug but probably not. :-) I'm now re-applying all my changes in smaller steps to see if I can figure out how this happened. |
Beta Was this translation helpful? Give feedback.
-
@augustoproiete BTW... excellent guess about the app being a launcher of another process, although it's a bit more than that. The app is my TestCentric GUI test runner for NUnit tests. It launches, controls and displays output from multiple agent processes, which actually run the tests. It is, in fact terminating early... before all the work is done... but only when run in my CI script. |
Beta Was this translation helpful? Give feedback.
-
@augustoproiete Well, surprisingly, that was not it. Here is a snippet of code I am using to launch the Gui in order to run its own tests. string executablePath = BuildSettings.OutputDirectory + "testcentric.exe"; // Works correctly
//string executablePath = "testcentric.exe"; // Returns prematurely
return BuildSettings.Context.StartProcess(executablePath, new ProcessSettings()
{
Arguments = arguments,
WorkingDirectory = BuildSettings.OutputDirectory
}); The uncommented line gives an absolute path and the call to The same thing happens if I use FilePaths rather than strings or if I use the longer form to return a process and wait for it to complete. This is using Cake.Tool 2.3.0, which is pretty mature, so... surprising. :-) I have a workaround now, which is to only set the absolute path when I am running, because BuildSettings is guaranteed to be competely initialized at that point. Do you want an issue for this? |
Beta Was this translation helpful? Give feedback.
-
It appears that StartProcess has spontaneously started acting differently in my code. Of course, I doubt that's the case - I probably did something in my own code - but I can't figure out what.
What is happening is that I call
StartProcess(FileName, ProcessSettings)
and the process starts (It's a GUI so I can see it running) but the next line of code executes immediately. Since that line is looking for the output file created by the process, it fails.Looking for any ideas on how or why this is happening or on how to debug it.
Beta Was this translation helpful? Give feedback.
All reactions