|
-
Jan 6th, 2006, 08:30 AM
#1
Thread Starter
Fanatic Member
How to use the command promp from C#? [resolved]
Hello!!!
I want to execute a command from c# as if it was executed from the
command prompt...
how can I do that?
thanks!!
Last edited by dekelc; Jan 7th, 2006 at 04:25 PM.
Dekel C.
-
Jan 6th, 2006, 09:29 AM
#2
Re: How to use the command promp from C#?
VB Code:
Dim psi As ProcessStartInfo = New ProcessStartInfo("cmd.exe")
psi.RedirectStandardOutput = True
psi.RedirectStandardInput = True
psi.UseShellExecute = False
psi.CreateNoWindow = True
Dim p As Process = Process.Start(psi)
p.StandardInput.WriteLine("ren c:\a.txt b.txt")
p.StandardInput.WriteLine("exit")
PHP Code:
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe");
psi.RedirectStandardOutput = True;
psi.RedirectStandardInput = True;
psi.UseShellExecute = False;
psi.CreateNoWindow = True;
Process p = Process.Start(psi);
p.StandardInput.WriteLine("ren c:\a.txt b.txt");
p.StandardInput.WriteLine("exit");
-
Jan 6th, 2006, 09:34 AM
#3
Thread Starter
Fanatic Member
Re: How to use the command promp from C#?
well, that's great for vb and php developers... but what about c#?
-
Jan 6th, 2006, 09:43 AM
#4
Re: How to use the command promp from C#?
That is for C#. In PHP tags. For color formatting. Forgive my transgression.
-
Jan 6th, 2006, 09:52 AM
#5
Thread Starter
Fanatic Member
Re: How to use the command promp from C#?
do I need to add a "using" reference for ProcessStartInfo?
because it doesn't reognise it...
-
Jan 6th, 2006, 10:04 AM
#6
Re: How to use the command promp from C#?
-
Jan 6th, 2006, 10:49 AM
#7
Thread Starter
Fanatic Member
Re: How to use the command promp from C#?
-
Jan 7th, 2006, 09:45 AM
#8
Re: How to use the command promp from C#?
-
Jan 8th, 2006, 05:33 AM
#9
Re: How to use the command promp from C#? [resolved]
Bear in mind that if its just a single command you can tag it onto the end of the call to start "cmd.exe" .
-
Jan 8th, 2006, 05:47 PM
#10
Thread Starter
Fanatic Member
Re: How to use the command promp from C#? [resolved]
hey penagate! how do I do that in code?
I mean, use the start command??
-
Jan 8th, 2006, 07:51 PM
#11
Re: How to use the command promp from C#? [resolved]
Process.Start(appPath, argString);
e.g.
Process.Start("cmd", @"ren c:\a.txt b.txt");
-
Jan 10th, 2006, 03:10 AM
#12
Lively Member
Re: How to use the command promp from C#?
 Originally Posted by mendhak
VB Code:
Dim psi As ProcessStartInfo = New ProcessStartInfo("cmd.exe")
psi.RedirectStandardOutput = True
psi.RedirectStandardInput = True
psi.UseShellExecute = False
psi.CreateNoWindow = True
Dim p As Process = Process.Start(psi)
p.StandardInput.WriteLine("ren c:\a.txt b.txt")
p.StandardInput.WriteLine("exit")
PHP Code:
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe");
psi.RedirectStandardOutput = True;
psi.RedirectStandardInput = True;
psi.UseShellExecute = False;
psi.CreateNoWindow = True;
Process p = Process.Start(psi);
p.StandardInput.WriteLine("ren c:\a.txt b.txt");
p.StandardInput.WriteLine("exit");
Hello. Im trying to do the same thing but with a telnet window.
Telnet will not allow you to redirect the standard IO
Can you please tell me how I can send commands to the telnet without using sendkeys.send()?
Maybe you could look at my thread
http://www.vbforums.com/showthread.php?t=380589
-
Jan 15th, 2006, 05:46 PM
#13
Thread Starter
Fanatic Member
Re: How to use the command promp from C#? [resolved]
well mendhak, it doesn't work after all...
I just tried it for the first time and it faild...
sorry...
maybe I need to add an "Enter" key after each line?
thanks
-
Jan 17th, 2006, 06:00 AM
#14
Re: How to use the command promp from C#? [resolved]
 Originally Posted by dekelc
well mendhak, it doesn't work after all...
I just tried it for the first time and it faild...
sorry...
maybe I need to add an "Enter" key after each line?
thanks

A 'writeline' includes an 'enter'. It sends the whole command.
What failed, what did you get instead?
-
Feb 15th, 2006, 07:19 PM
#15
Thread Starter
Fanatic Member
Re: How to use the command promp from C#? [resolved]
ok... It's working! thanks!
but is there a way to know if my commands succeeded?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|