@Adithya said in Execute commands in git bash using QProcess:
And yes my intention is to run multiple commands in one session of git bash (That was the reason I was trying via write().) .
Then we need a couple of minor modifications your original code:
process->start("C:\\Program Files\\Git\\git-bash.exe", QStringList());, or process->start("C:/Program Files/Git/git-bash.exe", QStringList());.
No arguments, though you should check the git-bash documentation to see if that wants any special arguments for your case where its input/output is piped.
process->write("ls\r\n");. Your order of the CR-LF is the wrong way round. I don't know whether you need the \r, or even if that will upset it and it wants \n only. You might want a "flush" after each write.
You call process->readAllStandardOutput() immediately after waitForStarted(), that is/could be too early.
You only call waitForReadyRead()/readAll() once. That is (potentially) not enough, output could come back in multiple, separate chunks.
You are relying on the output from the bash/command all being flushed from the other end for you to receive it. You had better hope their implementation does that! If you notice only partial data back to you, this could be the reason.
You are using the ("nasty") blocking/synchronous waitFor...() calls. If you run into trouble this way/things don't behave as you expect, change over to the asynchronous signals/slots methods of QProcess.
Don't forget to close your process/free it!