G Guest Apr 29, 2007 #1 I have a .NET VC++ program, I want to execute some dos command from the program, e.g. copy some file, and etc. How do I do that?
I have a .NET VC++ program, I want to execute some dos command from the program, e.g. copy some file, and etc. How do I do that?
C Cholo Lennon Apr 29, 2007 #2 - (C/C++) std::system - (C++ CLI) System:iagnostics:rocess::Start (in this case, you must use cmd.exe /k like a base process and a former command line)
- (C/C++) std::system - (C++ CLI) System:iagnostics:rocess::Start (in this case, you must use cmd.exe /k like a base process and a former command line)
G Guest Apr 29, 2007 #3 Dear Cholo: Can you provide more details about the actual codings and how to pass the copy command to cmd.exe. I tried System:iagnostics:rocess::Start ("cmd.exe", "copy FILEA FILEB"); But this does not work. The only thing the program does is to pop up the DOS prompt command window without actually executing the copy command. Also how to make the DOS prompt command window to go away from the program after the copy command is done?
Dear Cholo: Can you provide more details about the actual codings and how to pass the copy command to cmd.exe. I tried System:iagnostics:rocess::Start ("cmd.exe", "copy FILEA FILEB"); But this does not work. The only thing the program does is to pop up the DOS prompt command window without actually executing the copy command. Also how to make the DOS prompt command window to go away from the program after the copy command is done?
C Cholo Lennon Apr 29, 2007 #4 You should use an extra parameter with cmd.exe (/k or /c) (check cmd help typing cmd /? ). Also you can use the && operator to concatenate commands Your code must look like this: using namespace System:iagnostics;. // In one line Process::Start("cmd.exe", "/c dir && pause"); // Executing with hidden console ProcessStartInfo^ pSi = gcnew ProcessStartInfo("cmd.exe"); pSi->Arguments = "/c copy xxx yyy && delete xxx"; pSi->WindowStyle = ProcessWindowStyle::Hidden; Process::Start(pSi);
You should use an extra parameter with cmd.exe (/k or /c) (check cmd help typing cmd /? ). Also you can use the && operator to concatenate commands Your code must look like this: using namespace System:iagnostics;. // In one line Process::Start("cmd.exe", "/c dir && pause"); // Executing with hidden console ProcessStartInfo^ pSi = gcnew ProcessStartInfo("cmd.exe"); pSi->Arguments = "/c copy xxx yyy && delete xxx"; pSi->WindowStyle = ProcessWindowStyle::Hidden; Process::Start(pSi);