Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm using Visual Studio 2005 and C++ with both Win32 and MFC. I'm wondering if there is a way to use the command line to communicate with my program, while the program is already running. So, for instance, while my program is running, I'd like to be able to use the command line to tell it to do something. How do I do this??

Thanks!
Posted

There are many ways in which you can do interprocess communication like pipes, windows messages, events etc.
To use these from the command line, you must use some sort of scripting language like perl or you will need to write a utility and then run it from the command line.
 
Share this answer
 
You can't use the commandline to do that. You could make your program provide a "command window" of it's own that would allow you to have it "do stuff" when you type something in.

You could also write another commandline app that you could pass parameters to that would then instruct your alreay running application to do something. There are a few ways to go about ddoing this, and I suggest you google the phrase "MFC interprocess communications" to get an idea of what's available to you.

I think I still have some code at home that uses registered messages to transfer data back and forth between applications. If I remember, I'll see what I have, and send it to you if you're interested.
 
Share this answer
 
v2
You could do this, have the app handle the command line. If an instance is already running, then the current instance will send a message to that instance telling it what to do and then exit. If an instance is not running, the current instance will start and proceed to execute the "command".

As to how the 2nd instance can communicate with the first, there are several options you can choose from. The simplest would be WM_COPYDATA, and if your app is a console app, you could still have a hidden window merely to handle messages.
 
Share this answer
 
A quick and dirty way would be using a simple text file to issue directives to your application.
:)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900