Solved Correctly use QProcess to read stdout and write stdin
-
Hi and welcome to devnet,
Did you try using the asynchronous API ?
What about passing the parameters as a QStringList as is recommended ? Does it yield the same result ?There's no error checks done, you should add them.
-
Hi @SGaist, thanks for the reply!
I can't use the asynchronous as I cannot proceed to other commands and hardware controls until I can verify these commands have taken successfully. I had also tried passing the QStringList as the second argument into start() and also tried adding QIODevice::ReadWrite as the third arg as well.
What Error checks are you referring to? Error checks in the QProcess object?
I did try "emit updateTestProgressText("QProcess Error: " + vivadoConn.errorString());" and got "QProcess Error: Process operation timed out"
I should add that I can run the same program with the same arguments and environment in a batch script in windows, and get the tool command line to show.
Thank you for your time!
-
@MNorvalls said in Correctly use QProcess to read stdout and write stdin:
and get the tool command line to show.
What do you mean by that ?
-
Running this executable from the command prompt has the tool execute a CLI based TCL command line to interface with their Xilinx tools. You can tell the tool command line is active because instead of the cmd prompt "C:/>", the tool prompt becomes "vivado_lab%", that is what I mean by getting the tool command to show.
Does that make sense? I have also included a screenshot below :)
-
One thing I just saw, split the "-mode" and "tcl" in the argument list. Each element that appears on the command line is a separate element of the list.
-
So, I was not using the argument list in that snippet of code but had tried it before and it didn't work. With your suggestion, the arguments now work (process does not crash immediately). I was tagging them onto the command string because I could get the process to run before in that case. I assume passing the arguments in a QStringList is the proper way to use QProcess::start() so I will use that moving forward.
I have tried both of these argument methods and they both run because if I change the mode to gui, I get the Xilinx GUI window after a short amount of time.
Unfortunately, passing arguments the way you recommended still yields no output when reading.
-
Does it open it in a new command line window or in the same one that you call the application in ?
-
@MNorvalls said in Correctly use QProcess to read stdout and write stdin:
I am expecting the command line prompt "vivado_lab%".
It may be that the shell will not send an output prompt if it detects that standard input is not a terminal.
Outside of Qt, you should be able to test redirecting stdin or stdout from/to a pipe (
<
,>
,|
) to see what can actually be captured.And you should be capturing stderr as well as stin/out, if you are not doing so already.
-
@MNorvalls said in Correctly use QProcess to read stdout and write stdin:
args.append("-mode tcl");
This is wrong, they're two arguments.
-
@Christian-Ehrlicher We've moved on from that now, Christian :)
-
Thanks guys, yes it seems to be the executable that does not want to output its stdout in the tcl mode. I can see output if I call it in GUI mode (but obviously the GUI starts up instead). I am just going to have it write output to a file unfortunately.
@SGaist The tcl command line opens in the same command window. When calling the GUI mode, some output shows in the command window, and then the GUI appears in its own window.
@JonB I will give the command line piping a try as well for curiosity's sake, thank you.
Thanks for the help!