Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. I'm working on a program and I need to pass arguments to a process (process.startinfo.arguments), but the problem is that the process is already running. How do I acomplish this? Thanks!
Posted

1 solution

You cannot do it to an arbitrary already running process using command-line arguments. The process has been started already and those arguments are already obtained and processed at this moment. It's too late to change its behavior.

However, you can design your process in some special way to implement something pretty similar. This process should communicate with second instance of the same application, which would be a separate process. Using IPC, your second instance should communicate with the first instance and pass required data (say, taken from different command-line arguments you supplied on second run). Your first instance should listen to such connection and data and modify its behavior accordingly.

Actually, I designed a pretty elegant utility for such communications, which also can be used for implementation of single-process behavior of the application. I described it in my past answers:
Custom Windows right-click command launching multiple instances[^],
Enter multiple commands to only one process instance[^].

Actually, the author of the second question got to the same idea as yours; and I answered to that question.

—SA
 
Share this answer
 
v3
Comments
Samuel Dudík 8-Jan-15 8:22am    
Thank you for your answer! I admit, that I forgot to answer when I got it working (from hapiness). In the end, I did it by toggling the console to open, write the command I needed and simulating Enter press.
Sergey Alexandrovich Kryukov 8-Jan-15 11:34am    
You are very welcome. (Don't worry about the time of your replies, not a problem at all.)
Good luck, call again.
—SA

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