0

I have a process, which takes some arguments. I want it to start from C#. I have tried the same arguments in shortcut and it works. On the other hand, in c# it doesnt, so here are the arguments. The argument format is correct, but i get a wrong argument error at -k

ProcessStartInfo prf = new ProcessStartInfo("C:\\" + "argstest.exe");       
prf.UseShellExecute =true;
prf.Arguments = "-l http://test.tes1:testa@testb.testing.com:3333/ -k testing TYPE=0 USER=1 COUNT=10";
Process.Start(prf);

Process starts, but closes instantly, because the -k argument which should be testing doesnt get sent to program. I have tried adding a " " space before -l but same, also tried @" -l ..."

callmebob
  • 6,128
  • 5
  • 29
  • 46
user1422473
  • 117
  • 1
  • 3
  • 9

3 Answers3

1

Try to use verbatim string in arguments parameter. Like this:

prf.Arguments = @"-l http://test.tes1:testa@testb.testing.com:3333/ -k testing TYPE=0 USER=1 COUNT=10";
Anthony
  • 500
  • 3
  • 14
  • @user1422473 Please, post some more C# code (edit a question). We need to see lines, where you start a process. Maybe a problem is there. – Anthony Mar 16 '13 at 21:28
  • 1
    There is no character or escape sequence that changes meaning when using a verbatim string, so it would be quite surprising that this change alone would make it work. – Christian.K Mar 17 '13 at 11:25
1

I tested your code and did not find any issues. Perhaps you find this useful in tracking down your problem, I did this and you can do the same:

The Console App that you are trying to run, I did this:

static void Main(string[] args)
{
    foreach (var arg in args)
    {
        Console.WriteLine(arg);
    }
    Console.ReadLine();
}

From another console app, just this:

static void Main(string[] args)
        {
            ProcessStartInfo prf = new ProcessStartInfo("ConsoleApplication1.exe");
            prf.UseShellExecute = true;
            prf.Arguments = "-l http://test.tes1:testa@testb.testing.com:3333/ -k testing TYPE=0 USER=1 COUNT=10";
            Process.Start(prf);
        }

The output:

-1
http://test.tes1:testa@testb.testing.com:3333/
-k
testing
TYPE=0
USER=1
COUNT=10

This is what leads me to believe the problem isn't on the Process.Start() side, but in the way that your other app is parsing the arguments. As for why the shortcut works and this doesn't, maybe you should copy/paste the shortcut that you are using, not really sure on that one.

Mike C.
  • 3,024
  • 2
  • 21
  • 18
0

The way I found that works best for this is to set it up with an escaped quote around your command, like so:

string command = "ping -c 4 google.com";

ProcessStartInfo procStartInfo = new ProcessStartInfo("/bin/bash", "-c " + "\"" + command + "\"");