PDA

View Full Version : QProcess to interact with a command-line based windows executable on linux



AnnM
29th July 2013, 22:41
Hi!

I'm having a lot of trouble getting my QProcess to interact with an executable file. Just a bit of background, I have a QT application in Linux and I'm trying to import some data (electromagnetic tracker) from an existing Windows executable to use in my linux code. This windows executable is able to stream the data I need after first connecting to the tracking device over the network. I'm using wine to run the executable in linux, and it works great with the command line. What I want though, is to have my QT application (a simulation with a haptic device) to automatically run the executable, input the commands needed to start data acquisition (i.e. connect to the correct IP address for the device and enter a few specific commands like numbers and enter key presses).

I am able to get xterm (or gnome-terminal) to run my windows executable with the following commands:
QObject *parent;
....
QString arguments;
arguments <<"-e" << "wine ./{path to exe}/{name}.exe"; // stuff in {} is specific to my program. the path and name is correct.
QProcess *myProcess = new QProcess(parent); // this might be unnecessarily complicated with the parent.
myProcess->start("xterm",arguments); // here the windows executable command line interface shows up on the new terminal.
myProcess->write("1\n"); // THIS AND BELOW DON'T WORK. using the wait until complete function doesn't help
myProcess->write(" {dev IP address} 0/n");
myProcess->write("19/n");
myProcess->write("20000/n");
<here I'm expecting to see data streaming on the terminal>
-------

When the terminal window opens, I am actually able to manually enter the necessary commands, and the program works fine. However, I can't figure out how to input the commands automatically with my QT code. After extensive searching online, I thought it might have something to do with not starting bash so I added that to my argument list, but with that addition, it looked like my executable didn't start and neither did the new terminal. Also, hopefully this bug isn't due to wine - I can't avoid that! Any help would be greatly appreciated!!

Thanks!
Ann

PS - I still haven't tried to collect data from the terminal and plan to do so with myProcess->readAllStandardOutput() once I can actually get data to stream. If you forsee any issues with that, please let me know!

yeye_olive
30th July 2013, 08:37
QProcess::write() writes to the executed process' standard input. The process you execute is xterm, not wine. Are you sure xterm forwards everything it reads on its standard input to wine's? If I were you, I would try executing wine directly.

The same goes for reading the data output by the process. QProcess::readAllStandardOutput() will read xterm's standard output, not wine's.

ChrisW67
30th July 2013, 10:44
QObject *parent;
....
QString arguments;
arguments <<"-e" << "wine ./{path to exe}/{name}.exe"; // stuff in {} is specific to my program. the path and name is correct.
QProcess *myProcess = new QProcess(parent); // this might be unnecessarily complicated with the parent.
myProcess->start("xterm",arguments); // here the windows executable command line interface shows up on the new terminal.
myProcess->write("1\n"); // THIS AND BELOW DON'T WORK. using the wait until complete function doesn't help
myProcess->write(" {dev IP address} 0/n");
myProcess->write("19/n");
myProcess->write("20000/n");
<here I'm expecting to see data streaming on the terminal>

Line 7: Windows applications expect CR LF ("\r\n") not just LF ('\n');
Line 8, 9, and 10: "/n" is not a new line.

AnnM
31st July 2013, 01:32
@yeye_olive Yes, I think you're totally right. I had tried both ways with xterm as I wrote in the post above, and also with myProcess->start("wine ./..{path}/{name}"). I didn't think the second way worked because I couldn't see anything printed on the console and was assuming it would. I did know that the executable was started (checked with system monitor) however I didn't know if the commands were getting through so I switched to trying xterm because then I could actually see what was going on. I just added a ton of readAllStandardOutput() commands and it looks the program is working just fine! Thanks for writing back!

This post is solved but I'm not sure how to change the title!