views:

1175

answers:

1

I know of the Shell method to run files, but how can I execute normal command prompt commands like nslookup, and capture the output as a string?

Thanks for the help! Every google search has just turned up the shell method >_>

+1  A: 

There are many examples here on SO to System.Diagnostics.Process, which is what you'd need.

Since nslookup is and exe in windows - yes. If it was a built in command like say echo, then you'd use the cmd.exe as the program and using the arguments /c "echo hello program"

Edit: Here is another exmaple

To create a bat file, just open a text editor and add the command you want and save with a .bat extension.

Preet Sangha
Will that work for nslookup?
Cyclone
Here is the code I tried: System.Diagnostics.Process.Start("cmd", "echo hello program") which did not work. Also, is there any way to run this in some way that the actual command prompt does not open up, and you can capture the output?
Cyclone
I tried the answer given by Jeremy, it captured the start text every single time, and the command prompt opened anyway.
Cyclone
Also, I've no idea how to make a bat file, otherwise i could make it work >.>
Cyclone
google is your friend.
Preet Sangha