You can use System.Diagnostics.Process.Start
method to run any Windows cmd command, like starting it from the command line.
Sample code:
System.Diagnostics.Process.Start("py script.py");
题
I have created a new Windows Forms Application
Looks like picture (simplified)
...
Also I have a command line program (python)
It is saved in path as "myApp"
To run it, just need to type "myApp" (and pass it options) on command line
...
This is great, but I also want someone not familiar/comfortable with command line to
be able to use the program. Hence the form.
...
So question is, how can I set it up, such that on button click,
the form does the equivalent of typing directly to command line ??
...
I think this is possible because if I start a New Console Application, and code
system("myApp");
It does exactly this
...
However when I use the 'system' code in Windows Forms, I get a
'system': identifier not found
error
解决方案
You can use System.Diagnostics.Process.Start
method to run any Windows cmd command, like starting it from the command line.
Sample code:
System.Diagnostics.Process.Start("py script.py");
其他提示
You should use the Process
class with an appropriately set up ProcessStartInfo
. There's a detailed example at ProcessStartInfo
If thats the case i think we will have to do it the hard way.You could compile a seperate dll in visual studio to do exactly what your console application did,like system("fileneme")
and then set it to dynamically link with your form application at run time, and hopefully you will get it right.