Home All Groups Group Topic Archive Search About

Trouble with "Process's" please help!

Author
22 Aug 2006 7:24 PM
Matt
Ok so I'm trying to run a simple dos command shell through a VB.NET
2005 program.  The oddest thing is happening given the following piece
of code:


        '============================================================
        '=== VARIABLE DECLARATION AND INITIALIZATION ================
        '============================================================
            '---General Variables------------------------------------
                Dim CMDProcess As Process = New Process
            '---End General Variables--------------------------------
            '---XLNT Shell Variables---------------------------------
                CMDProcess.StartInfo.FileName = "cmd.exe"
                CMDProcess.StartInfo.Arguments = "\c md C:\temp\temp"
            '---End XLNT Shell Variables-----------------------------
        '============================================================
        '=== END VARIABLE DECLARATION AND INITIALIZATION ============
        '============================================================

        '============================================================
        '=== EXECUTE JOB AND KEEP TRACK OF TIME =====================
        '============================================================
            CMDProcess.Start()  <--- Does not work
            Process.Start("cmd.exe", "/c md C:\temp\temp") <---- Works


If I create a new instance of the "Process" object and then try to
start it, the command will not work.  But if I just simply call
Process.start the command works!

I need to be able to use the created object to do this job.  If anyone
could offer any thoughts I would be very appreciative.

Thanks
Matt

Author
22 Aug 2006 8:21 PM
Kim Greenlee
When you say the command doesn't work...what is the behavior?  Do you get any
errors, is there a message box, does an exception get thrown?  And if
so...what is the message?  

I’m wondering if the CMDProcess object is able to actually find cmd.exe.

Kim Greenlee

--
digipede - Many legs make light work.
Grid computing for the real world.
http://www.digipede.net
http://krgreenlee.blogspot.net
Author
22 Aug 2006 8:48 PM
Miro
I checked my process start program and the only difference I an see that I
have and you have is the
Dim of the Processes in the begining.  This works for me... dont know if you
want to see if it works for u.

my code is as follows:
Dim StartInfo As New ProcessStartInfo()
Dim myNewApp As New Process()

myNewApp.StartInfo.FileName = "C:\FILENAME.EXE"
myNewApp.StartInfo.Arguments = "/Q"
myNewApp.StartInfo.WorkingDirectory = "C:\Temp"
myNewApp.StartInfo.WindowStyle = ProcessWindowStyle.Normal

myNewApp.Start()


Miro


Show quoteHide quote
"Matt" <Kru***@gmail.com> wrote in message
news:1156274671.901073.38000@b28g2000cwb.googlegroups.com...
> Ok so I'm trying to run a simple dos command shell through a VB.NET
> 2005 program.  The oddest thing is happening given the following piece
> of code:
>
>
>        '============================================================
>        '=== VARIABLE DECLARATION AND INITIALIZATION ================
>        '============================================================
>            '---General Variables------------------------------------
>                Dim CMDProcess As Process = New Process
>            '---End General Variables--------------------------------
>            '---XLNT Shell Variables---------------------------------
>                CMDProcess.StartInfo.FileName = "cmd.exe"
>                CMDProcess.StartInfo.Arguments = "\c md C:\temp\temp"
>            '---End XLNT Shell Variables-----------------------------
>        '============================================================
>        '=== END VARIABLE DECLARATION AND INITIALIZATION ============
>        '============================================================
>
>        '============================================================
>        '=== EXECUTE JOB AND KEEP TRACK OF TIME =====================
>        '============================================================
>            CMDProcess.Start()  <--- Does not work
>            Process.Start("cmd.exe", "/c md C:\temp\temp") <---- Works
>
>
> If I create a new instance of the "Process" object and then try to
> start it, the command will not work.  But if I just simply call
> Process.start the command works!
>
> I need to be able to use the created object to do this job.  If anyone
> could offer any thoughts I would be very appreciative.
>
> Thanks
> Matt
>
Author
23 Aug 2006 12:21 PM
Phill W.
Matt wrote:

> Dim CMDProcess As Process = New Process

> CMDProcess.StartInfo.FileName = "cmd.exe"
> CMDProcess.StartInfo.Arguments = "\c md C:\temp\temp"

> CMDProcess.Start()  <--- Does not work
> Process.Start("cmd.exe", "/c md C:\temp\temp") <---- Works

Have a play with the StartInfo UseShellExecute property.
IIRC, that has some bearing on how things work.

Failing that, try "%COMSPEC%" instead of "cmd.exe"

Or, better still, looking at what you're actually doing:

System.IO.Directory.CreateDirectory( "C:\temp\temp" )

HTH,
    Phill  W.
Author
23 Aug 2006 1:14 PM
Matt
I'm not trying to create a directory, that was just something I tossed
in there to see if it would work.  What I'm ultimately trying to do is
to run dos commands from a VB.NET app.

I was under the impression given the following code.

Dim StartInfo As New ProcessStartInfo()
Dim myNewApp As New Process()


myNewApp.StartInfo.FileName = "cmd.exe"
myNewApp.StartInfo.Arguments = "\c md C:\temp\temp"
myNewApp.StartInfo.WorkingDirectory = "C:\Temp"
myNewApp.StartInfo.WindowStyle = ProcessWindowStyle.Normal
myNewApp.Start()

That the "Arguments" part of it would indicate what dos command I
wanted to execute.  When I run the following code I get a dos window
showing up but it doesn't make a directory.  How do I get it to execute
it?

The reason I want to do things this way is so that I can measure when
the process ends, whereas if I just did it like this...

Process.Start("cmd.exe", "/c " & Command)

I can't tell.
Author
24 Aug 2006 11:20 AM
Phill W.
Matt wrote:
> I'm not trying to create a directory, that was just something I tossed
> in there to see if it would work. 

Fair enough.

> myNewApp.StartInfo.FileName = "cmd.exe"
> myNewApp.StartInfo.Arguments = "\c md C:\temp\temp"

Shouldn't that be "/c md C:\temp\temp" ?

> The reason I want to do things this way is so that I can measure when
> the process ends, whereas if I just did it like this...
>
> Process.Start("cmd.exe", "/c " & Command)
>
> I can't tell.

That's because when you kick off a /Windows/ process from /DOS/, DOS
doesn't wait for it to finish /unless/ you use the START command with
the "/WAIT" flag, effectively

START /WAIT winprog1.exe a b c d
IF ERRORLEVEL 1 GOTO Boom

The VB.Net way to start and wait for a Process would be more like this:

    With myNewApp.StartInfo
       .FileName = "program1.exe"
       .Arguments = "a b c"
       .Start()
       .WaitForExit( ... ' can't remember the arguments; sorry
    End With

HTH,
    Phill  W.