how to run commandLine that uses cmd.exe in C#
-
Hi I would like write the function that does the same behavior of following C++ code. I tried to use the Process but I am sure I'm using it in worng way. Would you please guid me to the correct way to run the simple cmdLine? This is the way I use the Process and it opens the winzip application and does nothing. //progName = "c:\program files\winzip\winzip.exe" System.Diagnostics.Process.Start(progName, cmdLine); CString cmdLine; cmdLine.Format("wzunzip -d -o \"%s\" \"%s\"",fileName,folder);// setting command line System(cmdLine); //where cmdLine = "unzip "c:\a.zip" "c:\extractedfiles" Thank you.
-
Hi I would like write the function that does the same behavior of following C++ code. I tried to use the Process but I am sure I'm using it in worng way. Would you please guid me to the correct way to run the simple cmdLine? This is the way I use the Process and it opens the winzip application and does nothing. //progName = "c:\program files\winzip\winzip.exe" System.Diagnostics.Process.Start(progName, cmdLine); CString cmdLine; cmdLine.Format("wzunzip -d -o \"%s\" \"%s\"",fileName,folder);// setting command line System(cmdLine); //where cmdLine = "unzip "c:\a.zip" "c:\extractedfiles" Thank you.
Specify arguments by setting Arguments property of ProcessStartInfo object and pass it to Process class object
-
Specify arguments by setting Arguments property of ProcessStartInfo object and pass it to Process class object
Thank you for your answer Giorgi. I tried this way but got error... pStartInfo.CreateNoWindow = true; pStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; pStartInfo.UseShellExecute = false; //and also tried with Yes pStartInfo.Arguments = cmdLine; pStartInfo.FileName = progName; pStartInfo.RedirectStandardError = true; System.Diagnostics.Process.Start(pStartInfo);
-
Thank you for your answer Giorgi. I tried this way but got error... pStartInfo.CreateNoWindow = true; pStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; pStartInfo.UseShellExecute = false; //and also tried with Yes pStartInfo.Arguments = cmdLine; pStartInfo.FileName = progName; pStartInfo.RedirectStandardError = true; System.Diagnostics.Process.Start(pStartInfo);
What is the actual value of cmdline that you passed?
-
What is the actual value of cmdline that you passed?
The actual command line that I'm passing is: wzunzip -d -o "c:\sample.zip" "c:\outputfolder" in C++ I simple has to pass the string to system(cmdLine ) function, void ExtractZip(CStirng fileName,CString folder) { CString cmdLine; cmdLine.Format("wzunzip -d -o \"%s\" \"%s\"",fileName,folder);// setting command line System(cmdLine); }
-
The actual command line that I'm passing is: wzunzip -d -o "c:\sample.zip" "c:\outputfolder" in C++ I simple has to pass the string to system(cmdLine ) function, void ExtractZip(CStirng fileName,CString folder) { CString cmdLine; cmdLine.Format("wzunzip -d -o \"%s\" \"%s\"",fileName,folder);// setting command line System(cmdLine); }
Are all the arguments and parameters correct? What error are you getting? What happen if you run the program which you want to start from cmd with those arguments?
-
Are all the arguments and parameters correct? What error are you getting? What happen if you run the program which you want to start from cmd with those arguments?
-
You are right, Giorgi.. My argument isn't correct. I found my error and now is working great. Thanks for your advises and help. ^_^
You are welcome, glad that I helped you :)