Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
599 views
in Technique[技术] by (71.8m points)

process - C# Launch application with multiple arguments

I have been trying to start an application from a C# application but it fails to start properly. From the cmd the application plus the arguments launch a small window showing the output then the application in minimized to the system tray.

Launching the application from the C# application using the code below results in the process appearing in the task manager but nothing else, no output window, no system tray icon. What could be the issue?

    myProcess.StartInfo.FileName = ...;
    myProcess.StartInfo.Arguments = ...;
    myProcess.Start();

also tried passing the following

    myProcess.StartInfo.RedirectStandardOutput = true; //tried both
    myProcess.StartInfo.UseShellExecute = false; //tried both 
    myProcess.StartInfo.CreateNoWindow = false;

using

    Process.Start(Filename, args)

also did not work. Would really appreciate any help on how to tackle this.

UPDATE: I think the issue maybe the multiple arguments that are to be passed to the process

RunMode=Server;CompanyDataBase=dbname;UserName=user;PassWord=passwd;DbUserName=dbu;Server=localhost;LanguageCode=9

regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I don't see any mistake in your code. I have written a little program that prints out its args to the console

static void Main (string[] args)
{
     foreach (string s in args)
         Console.WriteLine(s);
     Console.Read(); // Just to see the output
}

and then I have put it in C:, being the name of the app "PrintingArgs.exe", so I have written another one that executes the first:

Process p = new Process();
p.StartInfo.FileName = "C:\PrintingArgs.exe";
p.StartInfo.Arguments = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18";
p.Start();

this gives me the desired output of the list of numbers. The app that calls PrintingArgs exits as it reachs p.Start(), this could be avoided by using p.WaitForExit(); or just Console.Read();. Also I have used both p.UseShellExecute and p.CreateNoWindow. Only in the case that

p.UseShellExecute = false;
p.CreateNoWindow = true;

makes the PrintingArgs app not to show a window (even if I put only p.CreateNoWindow = true it shows a window).

Now it comes to my mind that maybe your are passing the args in a wrong way and makes the other program to fail and close inmediately, or maybe you are not pointing to the right file. Check paths and names, in order to find any mistake you could omit. Also, using

 Process.Start(fileName, args);

does not uses the info you set up with StartInfo into your Process instance.

Hope this will help, regards


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...