Hi,
redirection is normally handled inside a shell, not in an external program.
cu, Bernd
--
redir.cpp:
#include <QDebug>
#include <QProcess>
int main(void)
{
// does not work, because i/o redirection is handled by a shell, not by QProcess or the external exe
// here the string "> c:\\out1" (!) is passed as an argument to argecho
qp1.
start("c:\\uti\\argecho.exe",
QStringList() <<
"> c:\\out1" <<
"1" <<
"2" <<
"3");
qp1.waitForFinished();
qDebug() << "qp1:" << qp1.readAll();
// this works (put the redirection before the external command!)
qp2.
start("c:\\windows\\system32\\cmd.exe",
QStringList() <<
"/C" <<
"> c:\\out2" <<
"c:\\uti\\argecho.exe" <<
"1" <<
"2" <<
"3");
qp2.waitForFinished();
qDebug() << "qp2:" << qp2.readAll();
return 0;
}
#include <QDebug>
#include <QProcess>
int main(void)
{
QProcess qp1, qp2;
// does not work, because i/o redirection is handled by a shell, not by QProcess or the external exe
// here the string "> c:\\out1" (!) is passed as an argument to argecho
qp1.start("c:\\uti\\argecho.exe", QStringList() << "> c:\\out1" << "1" << "2" << "3");
qp1.waitForFinished();
qDebug() << "qp1:" << qp1.readAll();
// this works (put the redirection before the external command!)
qp2.start("c:\\windows\\system32\\cmd.exe", QStringList() << "/C" << "> c:\\out2" << "c:\\uti\\argecho.exe" << "1" << "2" << "3");
qp2.waitForFinished();
qDebug() << "qp2:" << qp2.readAll();
return 0;
}
To copy to clipboard, switch view to plain text mode
argecho.c:
#include <stdio.h>
int main ( int argc, char ** argv )
{
int i;
for ( i = 0; i < argc; i++ )
printf( "%d: %s\n", i, argv[i] );
return 0;
}
#include <stdio.h>
int main ( int argc, char ** argv )
{
int i;
for ( i = 0; i < argc; i++ )
printf( "%d: %s\n", i, argv[i] );
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks