programmatically executing command line c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MedIt
    New Member
    • Feb 2008
    • 15

    programmatically executing command line c#

    Hi,
    I am using .net Process class to run an executable process , say abc.exe which takes three parameters- two input files(file1 & file2)
    and one output file(file3).Bas ed on the two input files, the o/p file3 is to be updated.
    The command line on the console will look like this:
    C:\dir\...> abc.exe file1 file2 -o file3

    On my c# code, I am doing something like:

    Process myProc = new Process();
    myProc.StartInf o.Filename = "dir\abc.ex e";
    myProc.StartInf o.Arguments = "file1, file2, file3";
    myProc.Start();

    It executes without giving any errors, but my o/p file3 is not updated.
    I am trying to figure out where I might have gone wrong to run this process.
    Or is there any other way to execute programatically the exe file?
    Please help!
    Thanks!
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    If your program is launched like this:
    Code:
    C:\dir\...> abc.exe file1 file2 -o file3
    Why are you doing this:
    Code:
    myProc.StartInfo.Filename = "dir\abc.exe";
    myProc.StartInfo.Arguments = "file1, file2, file3";
    Shouldn't you be doing this?
    Code:
    myProc.StartInfo.Filename = "dir\abc.exe";
    myProc.StartInfo.Arguments = "file1 file2 -o file3";

    Comment

    • MedIt
      New Member
      • Feb 2008
      • 15

      #3
      Originally posted by Plater
      If your program is launched like this:
      Code:
      C:\dir\...> abc.exe file1 file2 -o file3
      Why are you doing this:
      Code:
      myProc.StartInfo.Filename = "dir\abc.exe";
      myProc.StartInfo.Arguments = "file1, file2, file3";
      Shouldn't you be doing this?
      Code:
      myProc.StartInfo.Filename = "dir\abc.exe";
      myProc.StartInfo.Arguments = "file1 file2 -o file3";
      Sorry, thats my mistake:
      in my code it is actually:
      myProc.StartInf o.Arguments = "file1 file2 -o file3"

      Still no effect!

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        What if you put:
        Code:
        myProc.StartInfo.Arguments = @"file1 file2 -o c:\file3";
        Does the file at c:\file3 get created? It might be making that file somewhere other then where you think it should?

        Comment

        Working...