Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trouble getting errorlevel with Process.Start

396 views
Skip to first unread message

Vance Kessler

unread,
Apr 23, 2003, 10:43:32 AM4/23/03
to
I am having trouble determining what the errorlevel was set to by a
batch file, which I launch through Process.Start. I even echo out the
value of %errorlevel% just before the batch exits and it is set to 1,
but in my C# app the ExitCode property is 0.

The ONLY way I have found around this so far is to use the following
command as the last line of each batch file 'Exit %errorlevel%'.

I have tried setting the FileName property of my Proces object to the
batch file itself and launching it through 'CMD /C', niether work.

Here is basically what I am doing:

System.Diagnostics.Process oProcess = new
System.Diagnostics.Process();
oProcess.StartInfo.CreateNoWindow = false;
oProcess.StartInfo.UseShellExecute = false;
oProcess.EnableRaisingEvents = false;
oProcess.StartInfo.FileName = "TempCommands.bat";

oProcess.Start();
oProcess.WaitForExit();
if (oProcess.ExitCode != 0)
{
// NEVER GETS HERE!!!!
}

Nicholas Paldino [.NET/C# MVP]

unread,
Apr 23, 2003, 11:17:24 AM4/23/03
to
Vance,

I would think that the error code is zero because the command line
process executed successfully, which is what is really calling the batch
file.

Instead, I would process the output from the batch file, and process the
code yourself through the StandardError, StandardInput, StandardOutput
properties.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- nicholas...@exisconsulting.com

"Vance Kessler" <vkes...@peachtree.com> wrote in message
news:aeaf260b.03042...@posting.google.com...

Vance Kessler

unread,
Apr 24, 2003, 7:58:36 AM4/24/03
to
Nicholas, thanks for the suggestions, but they don't really help my
problem. I know the return code is from CMD.EXE, I just want to know
if there is another way to get it to return the actually ERRORLEVEL
other than by using the EXIT %ERRORLEVEL% line.

And I cannot really process the output of the batch file because it
sends out A LOT of output (potentially to both StdOut and StdErr).


Oh, and I guess you figured out some important information that I had
failed to mention, I am running this on Win2000 and WinXP.

"Nicholas Paldino [.NET/C# MVP]" <nicholas...@exisconsulting.com> wrote in message news:<ucPadvaC...@TK2MSFTNGP11.phx.gbl>...

manoj

unread,
Jan 16, 2008, 1:58:36 AM1/16/08
to
he exact question is i have to open first cmd and run this command

openvpn --management-query-passwords --cd "C:\Program Files\OpenVPN
\config" --management-hold --management 127.0.0.1 7536 --config "C:
\Program Files\OpenVPN\config\client.ovpn" --auth-user-pass

then i have to open one more command and execute this command


telnet

open localhost 7536


username Auth manoj

password Auth manoj

then u can see some thing happening in first command prompt

then i have to open 3rd command prompt and execute this one ipconfig

then it returns ip of the serve that should be display in text file


can any help it out

pls reply me to manoj...@gmail.com

Ignacio Machin ( .NET/ C# MVP )

unread,
Jan 16, 2008, 9:03:47 AM1/16/08
to
Hi,

You could try to use the RedirectStandardXXXX properties of the
ProcessStartInfo. It might work but it's not that easy (I think).
Additionally you could use a third party telnet client. nSoft has one and
I'm pretty sure that you can find some free ones.

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"manoj" <manoj...@gmail.com> wrote in message
news:e19292fc-19d9-4462...@k2g2000hse.googlegroups.com...

0 new messages