QProcess::start doesn't display a console window for console programs (Windows)
I see your point. I already figured that bare QProcess won't do what I need, so I'm experimenting with QProcess::startDetached("cmd.exe", QStringList() << "/C" << command, workingDir) strategy.
So what is it that you want exactly? I still don't quite get it...
Why not something like:
connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput()));
m_process.start( ... );@
QByteArray line = m_process.readLine();
printf("[childproc] %s\n", line.constData());
I want to have a command line in my program that would act exactly as if the commands are executed in a shell, with shell itself being launched implicitly. so if I want to launch any program I just type its name, press Enter and its window should appear, no matter console or GUI. But I should also be able to redirect output to a file with > symbol.
That sounds like you are trying to workaround all the "services" QProcess offers and you just want the plain "system()":http://www.cplusplus.com/reference/cstdlib/system/ command...
std::system would be good because I don't have to guess what shell the OS uses or which flags I need to execute my commands, but I can't set a working dir. That's crucial.
system() probably uses the working dir establish by chdir().
But if that doesn't work, you could also simply use a command like:
@"pushd c:\my_working_dir && do_something"@
The system() string is passed to the shell, so all shell commands work.
Anyway, if you decide to run "cmd.exe" manually, you should be using:
Any specific reason you've suggested pushd and not cd?
std::system doesn't cut it for me because it blocks until the shell exits, which is unacceptable. And I don't see a way to pass non-ASCII paths to it. So I'll have to use QProcess::startDetached after all.
[quote author="Violet Giraffe" date="1399141297"]Any specific reason you've suggested pushd and not cd?[/quote]
Because "cd" only changes the path, not the drive. At least on Windows.
At the same time "push" changes the path and drive, if required.
[quote author="Violet Giraffe" date="1399148562"]std::system doesn't cut it for me because it blocks until the shell exits, which is unacceptable. And I don't see a way to pass non-ASCII paths to it. So I'll have to use QProcess::startDetached after all.[/quote]
You could invoke it in a separate thread, so it doesn't block. And if you need Unicode support, just use _wsystem() on Windows with an UTF16 string. On Linux you can use the standard system() with an UTF8 string.
Thanks! I've googled for wide-string analog of system(), but couldn't find it.