Pratik
Pratik

Reputation: 11745

calling executable from a background process and passing a parameter to it

I have an Console application which runs as background process and there is an exe which needs to be called.This exe takes complete fill path as parameter and then encrypts that file. I did this way :

Process.Start( "myapp.exe" );

But what i want is this :

Process.Start( "myapp.exe file1.txt" ); // File1 is parameter of that exe

But this is not working. Looking for help & advice.

Thanks :)

Upvotes: 2

Views: 4091

Answers (5)

Tejas Sherdiwala
Tejas Sherdiwala

Reputation: 769

Process.Start(<the nameof the process>,<the parameters>) In your case

Process.Start("myapp.exe","file1.txt")

Upvotes: 0

Brad Bruce
Brad Bruce

Reputation: 7827

Process.Start("[drive]:\[directory]\myapp.exe", "file1.txt");

Substitute the actual drive and directory where indicated

Upvotes: 1

Shiv Kumar
Shiv Kumar

Reputation: 9799

Use something like this:

Process p = new Process();

p.StartInfo.UseShellExecute = false;

p.StartInfo.FileName = "myApp.exe";

p.StartInfo.Arguments = "file1.txt";

p.Start();

Upvotes: 1

anothershrubery
anothershrubery

Reputation: 21023

Try Process.Start("myapp.exe", "file1.txt");

Upvotes: 1

Pieter van Ginkel
Pieter van Ginkel

Reputation: 29640

You want to use the ProcessStartInfo class.

See http://msdn.microsoft.com/en-us/library/system.diagnostics.process.startinfo.aspx and http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx for an example on how to use this.

Use the Arguments property to set your arguments.

Upvotes: 2

Related Questions