Simple Process problem

L

Lloyd Sheen

I am trying to keep the process window open when I do the following:

Open a process with "cmd.exe"

Code is:

Dim myProcess As Process = New Process()
Dim s As String
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.WorkingDirectory = "C:\Lloyds Music\Blues On
C\Beverley Skeete - Unchained"

myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.CreateNoWindow = False
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = False
myProcess.StartInfo.RedirectStandardError = False
myProcess.Start()

Dim sIn As StreamWriter = myProcess.StandardInput

sIn.Write("dir /s" + Environment.NewLine)
myProcess.WaitForExit()

The actual work I will do will be different, this is only for testing to get
the process correct.

I do this and I can see the command window open and close. The WaitForExit
just falls thru since the process is complete. How do I keep the window
open after the commands I send complete?

I did try and add the following line:

sIn.Write("Pause" + Environment.NewLine)

but it did not make any difference.

Thanks
LS
 
L

Lloyd Sheen

Dennis said:
Maybe try something like...

Console.ReadLine() ' To force a pause in the program

There is no Console in this case. The CMD.EXE process has control.

LS
 
F

Family Tree Mike

Lloyd Sheen said:
I am trying to keep the process window open when I do the following:

Open a process with "cmd.exe"

Code is:

Dim myProcess As Process = New Process()
Dim s As String
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.WorkingDirectory = "C:\Lloyds Music\Blues On
C\Beverley Skeete - Unchained"

myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.CreateNoWindow = False
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = False
myProcess.StartInfo.RedirectStandardError = False
myProcess.Start()

Dim sIn As StreamWriter = myProcess.StandardInput

sIn.Write("dir /s" + Environment.NewLine)
myProcess.WaitForExit()

The actual work I will do will be different, this is only for testing to
get the process correct.

I do this and I can see the command window open and close. The
WaitForExit just falls thru since the process is complete. How do I keep
the window open after the commands I send complete?

I did try and add the following line:

sIn.Write("Pause" + Environment.NewLine)

but it did not make any difference.

Thanks
LS


If you pass a /K as the Process.StartInfo.Arguments property, then the
command window should stay. I don't however, think you can drive the
commands from standard input. I have always created a batch file to push
successive commands to the command window and specified the batchfile in the
arguments to cmd.exe.
 
D

Dennis

I am trying to keep the process window open when I do the following:

Open a process with "cmd.exe"

Code is:

Dim myProcess As Process = New Process()
Dim s As String
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.WorkingDirectory = "C:\Lloyds Music\Blues On
C\Beverley Skeete - Unchained"

myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.CreateNoWindow = False
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = False
myProcess.StartInfo.RedirectStandardError = False
myProcess.Start()

Dim sIn As StreamWriter = myProcess.StandardInput

sIn.Write("dir /s" + Environment.NewLine)
myProcess.WaitForExit()

The actual work I will do will be different, this is only for testing to get
the process correct.

I do this and I can see the command window open and close. The WaitForExit
just falls thru since the process is complete. How do I keep the window
open after the commands I send complete?

I did try and add the following line:

sIn.Write("Pause" + Environment.NewLine)

but it did not make any difference.

I tried your code as written (without the pause) and it works fine on my
machine. The cmd window stays open. When I close the cmd window the
WaitForExit finishes and the test program ends.
 
L

Lloyd Sheen

Family Tree Mike said:
If you pass a /K as the Process.StartInfo.Arguments property, then the
command window should stay. I don't however, think you can drive the
commands from standard input. I have always created a batch file to push
successive commands to the command window and specified the batchfile in
the arguments to cmd.exe.

Thanks that did it.

LS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top