Run dos command with Parameters

V

Vlad

I am trying to run the dos command "rename C:\Temp\MyTest1.txt
MyTest2.txt" from VB.net - to use the shell command I have found I
have to use a bat file otherwise I get an "The system cannot find the
file specified" error.

I am trying to use

Dim MyProcess As New ProcessStartInfo
MyProcess.FileName = "ren"
MyProcess.Arguments = "C:\Temp\MyTest1.txt MyTest2.txt"
Process.Start(MyProcess)

but I still get the error "The system cannot find the file specified"

How do I run a dos command with parameters from VB.Net

TIA

Andy
 
T

Tom Shelton

I am trying to run the dos command "rename C:\Temp\MyTest1.txt
MyTest2.txt" from VB.net - to use the shell command I have found I
have to use a bat file otherwise I get an "The system cannot find the
file specified" error.

I am trying to use

Dim MyProcess As New ProcessStartInfo
MyProcess.FileName = "ren"
MyProcess.Arguments = "C:\Temp\MyTest1.txt MyTest2.txt"
Process.Start(MyProcess)

but I still get the error "The system cannot find the file specified"

How do I run a dos command with parameters from VB.Net

TIA

Andy

That's because you have to run the command interpreter (cmd.exe on nt
based systems, command.com on 9x systems). So,it would look something
like:

MyProcess.FileName =
System.Environment.GetEnvironmentVariable("ComSpec")
MyProcess..Arguments = "-C ren C:\Temp\MyTest1.txt MyTest2.txt"

not exactly right I think, but pretty close.

Now.... If all your trying to do is rename a file, ahve you looked at
the System.IO.File.Move method?
 
V

Vlad

It needs to be the dos command as it is saved in one of the settings.

Your solution (I think it's \C not -c) is the best I've come up with -
the problem there is that it starts a new process which isn't handy if
your building a console app and want all errors to come back to the
users window.

Ta
 
T

Tom Shelton

It needs to be the dos command as it is saved in one of the settings.

Your solution (I think it's \C not -c) is the best I've come up with -
the problem there is that it starts a new process which isn't handy if
your building a console app and want all errors to come back to the
users window.
Ta

You are correct, I ment to put /c not -c. This is the only way your
going to be able to run dos commands - they have to be run by the
interpreter. You can of course, hide the window, and redirect the
output of the command so you can read it back and print it to you're
own window. Look at the RedirectStandardXXX methods on the
processstartinfo - oh, and make sure UseShellExecute is false.
 

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