Re: CreateProcess not working as doc specifies.
- From: "Gary Chanson" <gchanson@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 14 Jun 2005 14:21:03 -0400
"David Bennion" <David Bennion@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D9716C38-A76F-44BA-985B-0C7F8A4B8159@xxxxxxxxxxxxxxxx
>
>
> "Walter Briscoe" wrote:
>
> First, thanks for your reply.
>
> > In message <5EAB7DEB-B0F9-47D3-8CA7-D64844A1218C@xxxxxxxxxxxxx> of Mon,
> > 13 Jun 2005 13:50:17 in microsoft.public.win32.programmer.kernel, David
> > Bennion <David@Bennion.?.microsoft.com.invalid> writes
> > >I am having some difficulty using CreateProcess() to run a batch file and
get
> > >the same return code as I get from the command shell. I am trying to run
the
> > >batch in the manner suggested by the CreateProcess documentation, but it
> > >fails to run.
> > URL? or quotation.
>
> Here is the URL of CreateProcess:
>
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp
>
> I was just talking about the part of the doc that says to what I quoted
below.
>
> > >
> > >I am posting all of the background information below (sorry if the
wordwrap
> > >from the post obfuscates anything):
> > >
> > >Snippet of doc from CreateProcess() msdn doc:
> > >--------------------------------------------------------
> > > "To run a batch file, you must start the command interpreter; set
> > >lpApplicationName to cmd.exe and set lpCommandLine to the name of the
batch
> > >file."
>
> I had read this to mean "in this special case, set lpApplicationName to
> cmd.exe so that CreateProcess knows you are running something that needs to
> be interpreted with the command interpreter so it can be dealt with
> specially". The doc mentioned
> nothing about needing to pass special parameters to the command interpreter
> (/C) to get it to work, so I figured there *must* be some special handling
> they meant it to take in this case.
>
> I mean, as far as I can tell it makes no difference if you pass NULL in to
> lpApplication name and do it on the command line if you are going to use the
> cmd.exe /C method anway.
>
> > [snipped code]
> >
> > Tried your code in Visual C++ 6.0 SP 5 on Windows 2000 Professional SP4.
> > I snip my results:
> > // OK if(CreateProcess("C:\\winnt\\system32\\cmd.exe", "/C
C:\\DOCUME~1\\ADMINI~1.BRI\\LOCALS~1\\Temp\\david\\t.bat",
> > // US if(CreateProcess("cmd.exe", "/C
C:\\DOCUME~1\\ADMINI~1.BRI\\LOCALS~1\\Temp\\david\\t.bat",
> > // OK if(CreateProcess("C:\\winnt\\system32\\cmd.exe", "/C t.bat",
> > // US if(CreateProcess("C:\\winnt\\system32\\cmd.exe", "t.bat",
> > // OK if(CreateProcess(0, "t.bat",
> >
> > MSDN says about lpApplicationName: "will not use the search path".
> > Does this meet your need?
>
> Not really. I can successfully get the batch file to run, but getting it to
> run as it would run on the command line is the issue. When I run the batch
> file via "cmd.exe /C file.bat" either from the command line or via create
> process, it returns exit code 0. When I run the batch file from the command
> line, it returns exit code 1. But regardless of the way it is run the batch
> file thinks it should be returning 1 (see the results of the "echo
> %errorlevel%" at the end).
>
> At first I thought "oh, it's like unix. The batch file is returning 0
> because the exit code of the 'echo' command is 0. But echo is not actually
> an executable, it's part of the command interpreter so it doesn't affect the
> exit code".
>
> It clearly functions as expected when run from an active command window.
When you execute "cmd.exe /c ...", the return code is not the return code
of the executed command line. It's the return code from cmd.exe which is 0
because it successfully ran the command. As far as I know, there is no
provision for getting the return code from the command. All I can suggest is
that you have your batch file store the error level in a file or Registry key
so that your program can retrieve it.
--
-GJC [MS Windows SDK MVP]
-Software Consultant (Embedded systems and Real Time Controls)
- http://www.mvps.org/ArcaneIncantations/consulting.htm
-gchanson@xxxxxxxx
.
- Follow-Ups:
- Re: CreateProcess not working as doc specifies.
- From: Hector Santos
- Re: CreateProcess not working as doc specifies.
- From: Walter Briscoe
- Re: CreateProcess not working as doc specifies.
- From: David Bennion
- Re: CreateProcess not working as doc specifies.
- References:
- CreateProcess not working as doc specifies.
- From: David Bennion
- Re: CreateProcess not working as doc specifies.
- From: Walter Briscoe
- Re: CreateProcess not working as doc specifies.
- From: David Bennion
- CreateProcess not working as doc specifies.
- Prev by Date: Re: How to detect an application is done with certain operation
- Next by Date: Re: How to detect an application is done with certain operation
- Previous by thread: Re: CreateProcess not working as doc specifies.
- Next by thread: Re: CreateProcess not working as doc specifies.
- Index(es):
Relevant Pages
|
Loading