PDA

View Full Version : Qprocess-add commands to a running executable



Milardo
9th September 2010, 05:56
Hi,

If i have a .exe file running from that was started by QProcess commandProcess, how can I send additional commands to that running .exe file? Like if it was a media player that was playing some media (the .exe file) and I want to have a button on the gui pause it, what exact line of code could I use for that? Pause would be an argument probably. Thanks in advance.

tbscope
9th September 2010, 06:28
You use inter process communication.
There's a website about this on the qt documentation site.

Example: dbus or sockets

e8johan
9th September 2010, 11:02
The QProcess class can only send and receive information via stdin/out/err. You cannot use it to press buttons or such in another application.

Milardo
9th September 2010, 22:49
Can I get some complete examples? If I already have a exe file started by qprocess, what example code can I use to add additional commands or args to that exe file? Thanks

Urthas
10th September 2010, 00:06
I may very well be wrong here, but my understanding is that in order to "virtually" use a product (like a media player) that product has to expose an API. For example, Apple's iTunes API, which I have used to program a stripped-down iTunes interface in PyQt. I'd love to hear more about this however. :)

tbscope
10th September 2010, 06:26
http://doc.qt.nokia.com/4.6/intro-to-dbus.html

Talei
10th September 2010, 07:15
Although DBus is ATM available (at least officially) only on NIX (http://doc.trolltech.com/4.7-snapshot/ipc.html#d-bus), not on the windows - assuming that Milardo uses Windows and i.e. WMP.
Also I don't think (I can be wrong on this one) you can do what You want with QProcess either. If Your player don't support action like stop/pause/play from the CLI (this is really rare on win), then You can only (and again this is AFAIK, I can be wrong on this one) do a hook and override functionality directly.

For nix go with dbus.

tbscope
10th September 2010, 07:21
http://msdn.microsoft.com/en-us/library/aa365574(VS.85).aspx

You can always use sockets of course.

But indeed, if the program you want to interface with doesn't have a public api or doesn't expose an ipc option, then you don't have a lot to work with.

There is of course reverse engineering. You can always automate software from another one, but you need to use hooks.

Milardo
10th September 2010, 08:05
The exe program is gst-player.exe from gstreamer. It supports typing like pause, play from the command line. It is for windows os. If somebody can, please provide an example using dbus/sockets/hooks

tbscope
10th September 2010, 08:10
If the program accepts commands like that from any input then I guess you can just write "pause\n" or "play\n" to std out (for the environment where your process is running).

Milardo
10th September 2010, 19:25
Can you post an example of some code for that? That would be helpful thanks. I'm not that knowledgeable at programming but I do know some and I can learn fast.

Talei
10th September 2010, 22:23
In that case You can write something like that:

QProcess->write( "command" );
Of-course QProcess needs to be run at that time.

Milardo
11th September 2010, 02:39
Thanks for the code, it helped a lot. Here is a sampling of my code now.

In my mainwindow.cpp I have:

commandProcess.start("Path to gst-player.exe",args);

This starts the .exe file. To input additional commands that could be typed from command prompt to control the player I use:

commandProcess.write("pause\n");

This pauses the media file that is playing. That line of code works with other commands that can be typed at command prompt which control the player like "continue" "stop" quit". This all happens when I click buttons on a gui I am making/experimenting now. Hope this helps others too.