0

I am trying to run under QProcess the bash.exe from git. I've checked if the process is running and if the file exists and confirmed these but when trying to write to process a command and after that have "\n\r" it doesn't do anything.

Sample code:

QProcess *proc = new QProcess();
proc->start("C:\\Program Files\\Git\\bin\\bash.exe");
proc->waitForStarted();
proc->write("ls\n\r");
proc->waitForBytesWritten();
proc->waitForReadyRead();
# neither proc->readAll() nor proc->readAllStandardOutput(); fetch anything
# tried even proc->readAllStandardError(); but no luck as well.

So it just sits there and I don't get the directory listing. What might be the problem?

andreihondrari
  • 5,743
  • 5
  • 30
  • 59
  • `bash` expects its commands to be terminated by a line feed only, not a line feed and a carriage return, although I don't think that would explain the lack of output here, unless it is waiting for the full command that starts with `\r` to be entered. – chepner Aug 12 '14 at 18:49
  • `\n\r` is not a line ending on any system anyone is likely to be using and is most certainly **not** the line ending for `Windows`. – Etan Reisner Aug 12 '14 at 20:11

1 Answers1

1

First of all, I don't understand how your code even compiles, because there is no QProcess constructor that accepts string as an argument.

Here is what I would read the output of ls command using QProcess:

int main(int argc, char *argv[])
{       
    QProcess proc;
    proc.start("C:\\Program Files (x86)\\Git\\bin\\bash.exe", QStringList());
    if (!proc.waitForStarted()) {
        return 1;
    }
    proc.write("ls\n");
    QByteArray output;
    if (proc.waitForReadyRead()) {
        output += proc.readAll();
    }
    qDebug() << output;

    return 0;
}
vahancho
  • 20,808
  • 3
  • 47
  • 55