Results 1 to 4 of 4

Thread: QProcess to interact with a command-line based windows executable on linux

  1. #1
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QProcess to interact with a command-line based windows executable on linux

    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!
    Last edited by AnnM; 30th July 2013 at 04:29.

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QProcess to interact with a command-line based windows executable on linux

    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.

  3. The following user says thank you to yeye_olive for this useful post:

    AnnM (31st July 2013)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QProcess to interact with a command-line based windows executable on linux

    Qt Code:
    1. QObject *parent;
    2. ....
    3. QString arguments;
    4. arguments <<"-e" << "wine ./{path to exe}/{name}.exe"; // stuff in {} is specific to my program. the path and name is correct.
    5. QProcess *myProcess = new QProcess(parent); // this might be unnecessarily complicated with the parent.
    6. myProcess->start("xterm",arguments); // here the windows executable command line interface shows up on the new terminal.
    7. myProcess->write("1\n"); // THIS AND BELOW DON'T WORK. using the wait until complete function doesn't help
    8. myProcess->write(" {dev IP address} 0/n");
    9. myProcess->write("19/n");
    10. myProcess->write("20000/n");
    11. <here I'm expecting to see data streaming on the terminal>
    To copy to clipboard, switch view to plain text mode 
    Line 7: Windows applications expect CR LF ("\r\n") not just LF ('\n');
    Line 8, 9, and 10: "/n" is not a new line.

  5. The following user says thank you to ChrisW67 for this useful post:

    AnnM (31st July 2013)

  6. #4
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess to interact with a command-line based windows executable on linux

    @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!
    Last edited by AnnM; 31st July 2013 at 01:30.

Similar Threads

  1. Execute window command line-by-line using QProcess
    By nhocjerry in forum Qt Programming
    Replies: 5
    Last Post: 30th July 2013, 12:21
  2. Replies: 7
    Last Post: 15th November 2010, 09:00
  3. Replies: 0
    Last Post: 28th June 2010, 01:29
  4. Replies: 3
    Last Post: 23rd February 2010, 04:33
  5. QProcess and the command line
    By auba in forum Qt Programming
    Replies: 17
    Last Post: 27th May 2009, 10:39

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.