Solved Cannot write to a process
-
Even on windows it works only by accident. When you click on git.exe on windows there will be no command prompt which stays open - so no interaction possible.
-
@Christian-Ehrlicher You're joking. You must be. Did you ever hear about communication between processes? For example writing to other process stdin and reading from such process stdout?
-
@smallC said in Cannot write to a process:
For example writing to other process stdin and reading from such process stdout?
I did, but git does not do it (don't know how often I have to repeat it) - git is not interactive. Simply call 'git status' and you're done.
-
@Christian-Ehrlicher
Please post the code you want me to execute in order to get reply from git to the "git status" command.
I've tried the start command with program and params list and it doesn't work. -
@smallC
You are running a command of"/usr/bin/git"
, and then sending the string"git status\n"
to its standard input. That makes no sense at all, what wouldgit
begin to do with a command starting withgit...
even if it worked this way?I don't know what you claim it's doing under Windows. I don't want to get into a debate about that. Here you must be under Linux (
"/usr/bin/git"
), so if you don't agree and think what you had should work I invite you toman git
and find where you says it will read commands from stdin as you say rather than acceptstatus
as an argument which is what I/ @Christian-Ehrlicher say.Since you need to run
git status
you need to passstatus
as an argument on the command-line togit
. You need:process.start(git_process_path, QStringList() << "status"); // or, if you prefer process.setProgram(git_process_path); process.setArguments(QStringList() << "status"); process.start();
You can then read from its standard output. However, you really should also read from its standard error too, at present you are leaving anything it might write to stderr to vanish into the blue. Separately from that, for production code at least, you should be checking for error return code.
-
@smallC said in Cannot write to a process:
Please post the code you want me to execute in order to get reply from git to the "git status" command.
I've tried the start command with program and params list and it doesn't work.Please post your code - I won't write code for you. But basically it's just QProcess::start(), QProcess::waitForFinished() (not recommended, use signals/slots) and the QProcess::readAllStandardError()/QProcess::readAllStandardOutput()
-
@Christian-Ehrlicher
I did post my code. In OP. -
@JonB
Hi thanks,
That indeed worked. My mistake was that I was thinking of /usr/bin/git in terms of git executable on Windows.
Thanks for your help. -
@smallC
I think your original way worked under Windows because of thegit
implementation there, only. I look at https://gitforwindows.org/ and I see it talking aboutGit BASH
Git for Windows provides a BASH emulation used to run Git from the command line. *NIX users should feel right at home, as the BASH emulation behaves just like the "git" command in LINUX and UNIX environments.
and the screenshot at https://gitforwindows.org/img/gw1.png. I think they are saying in their Windows
git
that a command ofgit
alone enters a "shell", kind of emulating Linuxbash
, which allows you to type things likegit status
into it, and it stays there and executes. Perhaps not quite, but something like that anyway. That is not a facility ofgit
under Linux. probably why your stuff worked under Windows and not Linux? -
@JonB
Yes, in Windows it opens a bash/cmd and you can write/read from it. It works differently on Linux. I wasn't aware of that. I thought that the /usr/bin/git<<this git, is an equivalent to Windows git.exe. That's why the confusion.
Thanks for your help. -
@smallC
Indeed. FWIW, if you do want to support Windows too I think the Linux command-line-arguments-only will work there too, but not the other way round, though you'd have to verify.