After
I need to run a file that I create by creating a command prompt. Basically this is how it goes:
The name of the file is UArtCMD.exe, I have it by opening a command prompt in it's directory and run commands which are programmed in it Are used, for example "a uartcmd". What I'm trying to do is put this software out of a GUI and when, assume that a button is pressed on the GUI, this command will run using a command prompt.
I managed it to run my computer without any hits, but problems arise when I install the software on a separate computer because UArtCMD is an external software, on every computer If not, then what I tried to do is add to the resources of the project and run it from there, the problem I do not know is how to do this.
This is my code to run a command prompt on the computer that is the UArtCMD
public static string executeLine (string command) {string result, try the process process { Process.Start (New ProcessStartInfo ("cmd.exe" "/ c" + command) {CreateNoWindow = true, UseShellExecute = false, WorkingDirectory = "C: \\ UArtCMD", RedirectStandardError = true, RedirectStandardOutput = true}); Process.WaitForExit (); String text = process. StandardOutput.ReadToEnd (); Process.Close (); MainWindow.log (text); Result = text; } Hold (exception before) {Results = ex.StackTrace; } Return results; }
Thanks in advance!
If you need to add any information or make more detail on the question, then let me know that I will do this gladly.
- Include the reference of the file UATERCMD.exe in your solution (anywhere in the solution architecture
- Set your "Copy to Output Directory" property to "always" in the property.
- Set up your methodology to set the "Working Directory" property to "Environmental Content Directory."
Now the UArtCMD.exe should always go to the bin directory (even if it is created by a build agent in a strange output directory) and look in the same directory as the code code It's going to know from running.
Edit: Comment about removing the "Working Directory" property from your process object is valid; you can do this instead of setting it to "Environment.CurrentDirectory", they both work the same
Comments
Post a Comment