running cmd.exe using System.Diagnostics.Process

Hi guys,
I am running cmd.exe to start a executable from a web application.Howvever, i need to input 2 more parameters for the account and pwd as shown below.
CMD.EXE
c:\Documents and setting\desktop>perl scriptest.pl test.txt
account(domain/user): xxx
password:xxxx
'User enter perl scriptest.pl test.txt, then cmd.exe will prompt for account and password for user to enter.
How do i let the web application enter the account and password.?
My program is such
Dim proc As System.Diagnostics.Process
proc = New System.Diagnostics.Process
'Do not receive an event when the process exits.
proc.EnableRaisingEvents = False
'Start cmd.
proc.StartInfo.FileName = "cmd.exe"
Dim b As String = "/c perl scriptest.pl test.txt 'start the executable (I am able to start this but unable to read in my account and password)

Dim c As String = "/c student" 'enter the account
Dim d As String = "/c password" 'enter the password

proc.StartInfo.Arguments = b
proc.StartInfo.Arguments = c 'read in the account
proc.StartInfo.Arguments = d 'read in the password

proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardOutput = True
proc.StartInfo.CreateNoWindow = True
proc.Start()
Dim ad As String = proc.StandardOutput.ReadToEnd
SaveTextToFile(ad, Server.MapPath("write.txt"))
'Response.Write(ad)
proc.Close()
The web application run invoking the subroutine above but it doesnt give an output. My guess is the cmd.exe didnt take in the account and password i supplied above. How do i solve it?
Thanks for the help

[1734 byte] By [Ichiro] at [2007-12-16]
# 1
You could try to use the process.StandardInput to "write" information into your perl script.



proc.StartInfo.Arguments = "/c perl scriptest.pl test.txt"
proc.StandardInput.WriteLine("student") 'enter the account
proc.StandardInput.WriteLine("password") 'enter the password

This will only work if the perl script reads the data from standard input. This is not the case if the entered password shows as asteriks (***).

However, creating a new process for every request will not scale very well. If this page will be heavily used, you might look into converting your perl script to .NET.

DanielRieck at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Hi, I have a query that is in relation to this issue. I am trying to install MSDE from the command prompt and I would like to do this programmatically rather than manually (so I can put the code in an intaller). How do I enter details into the process and get it to excute that command? I have had a play around with the code above but I dont seem to be able to write to the command Prompt window. I need to send the following text to the cmd.exe and have it excute the code.

1st I need to redirect to the correct directory i.e. "CD C:\MSDERelA" excute,
and then I need to run the setup.exe i.e. "Setup.exe \qb+ INSTANCENAME=.. " etc. Can you point me in the right direction?

regards

Mark

MarkTheArcherEvans at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
You don't need to CD to the directory first. Just set the WorkingDirectory property on the process.

To pass the string "\qb+ INSTANCENAME=.." into the program, set it as the process' argument. The filename you execute is just "setup.exe".

Or did you mean something else?!

DanielRieck at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
This doesn't work at the Setup.exe has to be run from within cmd.exe. I have got this far...

Dim myprocess As New System.Diagnostics.Process

myprocess = New System.Diagnostics.Process

myprocess.StartInfo.WorkingDirectory = "C:\MSDERelA"

myprocess.StartInfo.FileName = "cmd.exe"

myprocess.StartInfo.Arguments = "Setup.exe/qb+ INSTANCENAME=LONGBOW DISABLENETWORKPROTOCOLS=1 SAPWD=sa"

myprocess.Start()

This does run the cmd.exe and set the working folder but i need to input and excute the 'Argument' once the exe is up and running.

I tried the method that you suggested but the windows installer (setup.exe) wont run like that, it just pops up with details of the intaller rather than installing the server onto the PC.

Mark64 at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
Well, if you know how to open a cmd prompt, and run a file, why not make a .bat file and simply run the program from the .bat file with all the arguements needed. This way, you don't really have to worry about that in your program.
Dustin.
Dustin_H at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6
Found this on another thread and for some reason this appears to work!

myprocess = New System.Diagnostics.Process

myprocess.StartInfo.WorkingDirectory = "C:\MSDERelA"

myprocess.StartInfo.FileName = "setup.exe"

myprocess.StartInfo.Arguments = "/qb+ INSTANCENAME=LONGBOW DISABLENETWORKPROTOCOLS=1 SAPWD=sa"

myprocess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

myprocess.EnableRaisingEvents = True

myprocess.Start()

myprocess.WaitForInputIdle()

myprocess.WaitForExit()

myprocess.Close()

regards

Mark

Mark64 at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...