How can I find out why the system is unable to launch my application?

I have a C ++ program that runs a command and passes some arguments. The code looks like this:

 int RunApplication(fs::path applicationPathName,std::string arguments)
 {
    std::string applicationShortPath=GetShortFileName(applicationPathName);
    std::string cmd="\""+applicationShortPath +"\"  "+ arguments+" >>log.txt 2>&1 \"";
    std::cout<<cmd<<std::endl;
    int result=std::system(cmd.c_str());
    return result;
 }

      

When I run a system command, the cmd window appears shortly and then closes, but the result is 1 and the cmd does not start (the command should generate output that is not generated).

To check if the cmd is correct, I stopped the application just before the system bar and copied / pasted the cmd content into the CMD window and it worked.

I am wondering how can I find why the application is not starting in system ()?

cmd has this value just before starting:

"D:/DEVELO~3/x64/Debug/enfuse.exe"  -w --hard-mask --exposure-weight=1 --saturation-weight=0.328 --contrast-weight=0.164 -o "C:/Users/m/AppData/Local/Temp/1.tif"  "C:/Users/m/AppData/Local/Temp/1.jpg" "C:/Users/m/AppData/Local/Temp/2.jpg"  >>log.txt 2>&1 "

      

How can I find why it is not working?

Is there a way that I installed the system so that it doesn't close the cmd window so I can check it?

Is there a better way to run a command on the OS?

Does Boost have any solution for this?

Edit

After running from cmd / k, I get this error message:

The input line is too long.

      

How can I fix this other than shortening the cmd line?

0


source to share


3 answers


Use cmd /k

to save terminal: http://ss64.com/nt/cmd.html



Or just type in cmd.exe

and check environment, permissions, etc. You can manually paste this command to see if it will work from this shell. If so, you know the paths, permssions and environments are okay, so you have another problem on your hands (escaping argument, character encoding problems)

0


source


There are two different things here: if you need to run a superprocess, "system" is not the best way to do it (it is better to use the appropriate API, for example CreateProcess

, or a multiplatform shell, but avoid going through the shell so as not to expose potential malware injection).

But in this case, system () is probably the right way to go, since you really need a command interpreter (you can't manage things like >>log.txt 2>&1

just creating a process.)

The problem looks like a glitch in the called program: maybe the path is wrong, or some of the files it is supposed to work with do not exist or are not accessible with the appropriate resolution, etc.



One of the most interesting things: open a command prompt and paste the line you posted there. It works? Does something indicate an error?

Another thing to check is how the escape sequence is used in C ++ literals: '\'

you need to get '\\'

, since the first is the escape for the second (for example, \n

or \t

, etc.). While it doesn't seem to be the case, it is one of the most common mistakes here.

+1


source


0


source







All Articles