Click here to Skip to main content
15,884,080 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
In my opinion, it should have the same result between launching a program from command line as:
<program path=""> <a-parameter>

and launching from another c# program by calling

C#
Process p = new Process();
p.StartInfo.FileName = @"D:\programs\cctv-workstation-sim\Release\CCTV Workstation.exe";
p.StartInfo.Arguments = wksSID;
p.Start();



But the fact is that the two ways of launching causes different result. In the beginning of program execution, the two launching is the same. But, in the latter stage, they act differently.

The launched & launching programs are in c#.

I should trace to understand what's wrong with it. But if anyone tells me the possible cause, it's more efficient.
Posted
Updated 30-Jul-15 21:02pm
v3
Comments
[no name] 31-Jul-15 2:32am    
"Act differently" has no meaning. You will need to provide information on exactly what differences you observe.
Stan Huang 31-Jul-15 2:43am    
The launching from command line behaves as I expected. It will pop up a drop list after receiving a packet from network. In command-line launching, it works as expected, as clicking on it by mouse. But in case of launching it by calling c# API, the drop list won't be popped up.
F-ES Sitecore 31-Jul-15 3:54am    
I'm going to take a guess that you are calling this code from an asp.net website. If that's the case then the exe is running on the server, not the client, and the account the code is running under doesn't have access to the desktop so can't show pop-ups etc.
Stan Huang 31-Jul-15 4:23am    
The caller & callee reside on the same PC. But your concern inspired something. I copied the caller into the same folder as the callee, it runs as expected.

The difference the two programs behave differently is probably because of the parameter you are passing to the program.
Check your parameters in both cases.
 
Share this answer
 
Comments
Stan Huang 31-Jul-15 3:09am    
I dumped the parameters and number of them in the beginning of the program, main() at program.cs, they are the same at both cases.
The possible reason is that the callee's environment is different in the two ways of launching. In case of launching it from another c# program, the callee may think it resides on the folder same as the caller.
I moved the caller into the folder of the callee and then the callee launched and runs as expected.
 
Share this answer
 
Comments
Alan N 31-Jul-15 7:21am    
It's good that you have the system working again but I hope that you can see that what you did should have been regarded as diagnosis of the problem and not the solution.

It's likely that the callee is making assumptions about the current directory. If the WorkingDirectory property of ProcessStartInfo is not set then the caller's current directory is used. I've always thought that this was stupid and a more sensible default would be the callee executable's directory.
Stan Huang 31-Jul-15 9:31am    
What you said is inspiring. The callee is from others and I wrote the caller to launch it. Maybe I need to pay more attention on issues around to prevent possible fault.

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