By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

Run dos command with Parameters

P: n/a
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

Oct 26 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Oct 25, 8:32 pm, Vlad <vladimir.mcbad...@gmail.comwrote:
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?

--
Tom Shelton

Oct 26 '07 #2

P: n/a
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
Oct 26 '07 #3

P: n/a
On Oct 25, 10:43 pm, Vlad <vladimir.mcbad...@gmail.comwrote:
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.

--
Tom Shelton

Oct 26 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.