Is it possible to build a standalone Windows app using Visual Studio that runs Command-line commands and/or scripts ?
-
Possible duplicate of C++ Executing DOS CommandsMikhail– Mikhail2017-08-07 02:00:29 +00:00Commented Aug 7, 2017 at 2:00
-
To what end? How would your proposed app be different from cmd.exe?Harry Johnston– Harry Johnston2017-08-07 03:54:13 +00:00Commented Aug 7, 2017 at 3:54
-
I am looking to make a GUI app that would run a command and/or script when a button is pressed.Ahmad Taj– Ahmad Taj2017-08-08 01:57:44 +00:00Commented Aug 8, 2017 at 1:57
Add a comment
|
1 Answer
Yes, you can do this, and you can do it in multiple languages too.
For C#, according to this question, you can run:
string strCmdText;
strCmdText= "p4.exe jobs -e";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);
In a nutshell, you can call the .NET API (see the Start documentation here ), and start an instance of CMD.exe (or bash or whatever else you want to call) and send it a command. You can get information on what the result of the script's run was using the properties and methods of the Process class.
2 Comments
Eryk Sun
Running a command line via CMD needs to start with
/c or /k and in general requires double quotes around the command line to avoid mangling quotes if the first argument in the command line is quoted and it's not the only quoted argument, e.g. "/c \"\"C:\\Program Files\\Some App\\p4.exe\" jobs -e \"Some Arg\"\"".Ahmad Taj
I mean is it possible to build a Windows app or widget with a GUI that will run a command, such as move files from one directory to another, by pressing a button.