1

I'm trying to execute a relative simple exe (that needs to get some input) that was made with VS. Using QProcess:

QProcess *process = new QProcess(this);
QDir::setCurrent(entire_path);
process->start(exe_name, QStringList() << ""); // for empty args

the thing is, that when I close the program, it says that my program (the one that i'm trying to execute), was destroyed while process. Also, if I use process->state(), it returns the value 2 - which means it's running. But, the thing is that no program appears.

Edit: the final solution needs to redirect the IO to files.

Edit 2: I also tried to open the exe from a c++ class, and to use that class in Qt, but it just open the cmd with this exe. If I use that class from a standard c++ main, the IO is from files, but using Qt, it just doesn't work.

I tried to open another program, like the calc, and it worked. So i have no idea what's the problem...

btw, I looked for other questions like this, didn't find any that helped...

1 Answers1

3

You should use QProcess::startDetached.

Because the QProcess class is designed as an QIODevice (it inherits QIODevice), QProcess controls started native process and the deletion of the QProcess instance causes the termination of the native process.

Update.

To retrieve the output from the Windows GUI process, according Qt docs, you might be able to use QProcess::ProcessChannelMode QProcess::SeparateChannels. From the Qt docs:

Note: Windows intentionally suppresses output from GUI-only applications to inherited consoles. This does not apply to output redirected to files or pipes. To forward the output of GUI-only applications on the console nonetheless, you must use SeparateChannels and do the forwarding yourself by reading the output and writing it to the appropriate output channels.

msrd0
  • 7,816
  • 9
  • 47
  • 82
Max Go
  • 2,092
  • 1
  • 16
  • 26
  • Thanks, it works, but the thing is that I didn't mentioned is that I want to use the setStandardInputFile and setStandardOutputFile methods, so I'll be able to test my program. with the startDetached method I cant do that. –  Sep 26 '14 at 18:31
  • 2
    If I understand correctly, OPs program is a command-line prog and he never sees the program appear. Is that correct? That could be, because you are spawning the process but no terminal process. Maybe you have to execute "cmd.exe /c " see: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true – Benjamin Maurer Sep 26 '14 at 18:52
  • yeah BenjaminMaurer, that's the case, but if I use that, how can I get the input and the output to a file or whatever? and N1ghtLight, thanks, but can it also get input from a file? –  Sep 26 '14 at 22:53
  • you should to try, I didn't try it myself. I'm wondering how this functionality can be implemented via cmd.exe too. – Max Go Sep 27 '14 at 07:50
  • http://stackoverflow.com/questions/16098366/can-i-send-some-text-to-the-stdin-of-an-active-process-under-windows as possible solution you can use call of PowerShell to achieve process standard input from a file. – Max Go Sep 27 '14 at 07:57