QProcess standard Input file question
-
Hi ,
I just saw that one can redirect the output of a program started form a QProcess through the
@
readyReadStandardOutput()
@signal ,I also saw that QProcess has
@
void setStandardErrorFile ( const QString & fileName, OpenMode mode = Truncate )
void setStandardInputFile ( const QString & fileName )
void setStandardOutputFile ( const QString & fileName, OpenMode mode = Truncate )
@methods.
Is it possible to send a command to a process started with QProcess through the standardInputFile?For example if I wanted to set a Ctrl +C command to a process to terminate it .Is it possible to do that?If so how .What is the intended use of the file set with
@
void setStandardInputFile ( const QString & fileName )
@Thank you for your time.
-
QProcess is an QIODevice implementation so you can send any input to the process by calling write().
When you use setStandardInputFile you're redirecting that stream to a file i.e. you can't write() to it anymore and the process you run will read input only from that file.
One use case I can think of is when you have some process with interactive configuration eg. it asks you for login, password and some other stuff and you're suppose to type it in. You can jam the answers in a file and feed that to the process via this mechanism. I don't think that's terribly useful because apps have usually switches for that sort of thing but nevertheless I can imagine some cases this comes handy. If you use windows command prompt this is the same as passing a file name with "< character":http://technet.microsoft.com/en-us/library/bb490982.aspx to the command.