简体   繁体   中英

Does System.Diagnostic.Process.Start() runs a .exe file correctly

I have written a simple console application in C# that takes two arguments. these two arguments are the name of input file and output file. This console app reads the data from input file and writes them to a new file with the output argument name. this program works correctly, when I run this program from CMD (command prompt) it works and the output file is created. But when I run this app from an other windows application that runs this below line, that was not create the file.

System.Diagnostics.Process.Start(@"C:\Users\Khodaei\Desktop\testExecuter\testExecuter\bin\Debug\testExecuter.exe", "input.csv output.csv");

Is there any limitation for running an .exe file from System.Diagnostic.Process.Start() ?

You can never be sure that the relative path will yield an absolute path that is within the desired directory. And that is exactly your problem here.

You should either provide an absolute path to both arguments within the second parameter of Process.Start , or make sure that the working directory is set as desired. Note that if a path contains spaces, you have to wrap it around in "" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM