Is there any equivalent in Windows to Unix Shell's "exec"? Basically, I need to avoid forking a new process, so that input/output pipes are preserved, as well as process id.

Edit:

So, here's my problem. I have a process A that starts a script, and this script ends by executing a process B. I need for A to get all of B's output, as well as be able to kill B by killing the process it has spawned (the script).

On Unix, executing B with exec does that job.

link|improve this question

71% accept rate
There is no equivalent, at least not using standard Windows commands and programs. – John Gardeniers Sep 24 '11 at 8:47
If you're trying to run an executable, rather than another batch file, there is no (supported/realistic) way of doing this. However, input/output pipes are normally inherited by applications running in a batch file. If you can describe why you want to do this, we may be able to suggest alternatives. – Harry Johnston Sep 25 '11 at 20:41
Process A should already get all of B's output, unless the script overrides this. Is this not working? – Harry Johnston Sep 26 '11 at 2:17
It is possible using the Win32 API to arrange for a child process to die when the parent process does, however there is no built-in command-line option AFAIK. If I provide some source code (for Visual C++) are you able to build it? – Harry Johnston Sep 26 '11 at 2:26
@Harry I'm forking the script from Java, so, if the idea is for process A to use that Win32 API, I'm afraid that's unlikely to work, though I'm thankful for the effort. Better just to explain it isn't possible, and I'll accept that as the answer. – Daniel C. Sobral Sep 26 '11 at 13:15
show 1 more comment
feedback

1 Answer

I think call does what you want, but I'm not 100% sure.

link|improve this answer
2  
If you want to run one batch file from another, without launching a new instance of cmd.exe, call is the right answer. – Harry Johnston Sep 25 '11 at 20:39
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.