Click here to Skip to main content
15,909,747 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
Here I am trying to execute command prompt through below Vb.Net coding.


but I can't figure out why this p.Arguments = com; is not working.but it's not showing any error

thanks in advance for any explanation

Regards,

Soumya

VB
Dim com As String = "md pp"
           Dim p As New ProcessStartInfo("C:\windows\system32\cmd.exe")

           With p
               '.FileName = Environment.SystemDirectory & "\cmd.exe"
               p.WorkingDirectory = TextBox1.Text
               ' here i m trying with this path "c:\myown\course-connect-0.13.3"

            
         p.Arguments = com

               p.WindowStyle = ProcessWindowStyle.Maximized
               p.RedirectStandardInput = True
               p.UseShellExecute = False


               Process.Start(p)
               Dim output As String = p.ErrorDialog
Posted
Comments
[no name] 17-Jul-12 9:09am    
The first question is why are you going through all the trouble of using the command prompt to create a directory? Why are you not using the built in features of .NET?
Sandeep Mewara 17-Jul-12 10:50am    
+1I too would like to know.

1 solution

Because "md" and "pp" are not recognised parameters to cmd.exe

If you look here: http://ss64.com/nt/cmd.html[^] you will find all the things that the cmd application will know.

And before you ask, I suspect that "md" will not work as a Process either, as it is a built in DOS command.

As Wes and Sandeep have said: use the framework command instead: Directory.CreateDirectory[^]
 
Share this answer
 
Comments
soumyaraj 17-Jul-12 12:03pm    
Hi,
Thank you for your Reponse

Actually I want to run the following command through .NET .when I set this command in to p.Arguments nothing is happening in dos prompt as well as in output folder

so pls let me know how to solve this issue

java -jar textbox1.text\CocoImport.jar -s textbox1.text\am-govt -d textbox2.text -f


Thanks & Regards,
Soumya
OriginalGriff 17-Jul-12 12:06pm    
Set the command to "java.exe" instead of "cmd.exe" and set the rest as the parameters.
You may need to locate the "java.exe" file and include it's path.
Trak4Net 17-Jul-12 14:51pm    
Did you look at the link provided above for cmd.exe parameters?
If you want to see the command window to watch the output of your java.exe look at using these parameters
Options
/C Run Command and then terminate

/K Run Command and then return to the CMD prompt.
This is useful for testing, to examine variables

Command : The command, program or batch script to be run.
This can even be several commands separated with '&'
(the whole should also be surrounded by "quotes")
soumyaraj 18-Jul-12 3:15am    
Hi All,

I could solve with the following code

ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.UseShellExecute = false;
processStartInfo.WorkingDirectory = "path";
processStartInfo.WindowStyle = ProcessWindowStyle.Maximized;
Process process = Process.Start(processStartInfo);

if (process != null)
{



string a= @"path -d";
string b = @"path -f";
process.StandardInput.WriteLine("java -jar CocoImport.jar -s " + a + " " + b +@"\");

//process.StandardInput.WriteLine("yourCommand.exe arg1 arg2");

process.StandardInput.Close(); // line added to stop process from hanging on ReadToEnd()

string outputString = process.StandardOutput.ReadToEnd();

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900