Вопрос

I do have a final issue to my project and I just can't see clear enought to find out what the hell is wrong here.

When I run my code with this, everything is just perfect:

    Dim p As Process = New Process()
    With p.StartInfo
        .WorkingDirectory = Environment.GetEnvironmentVariable("ProgramFiles") & "\rest_of_my_path\"
        .FileName = "ping"
        .Arguments = "192.168.0.24"
        .CreateNoWindow = True
        .UseShellExecute = False
        .RedirectStandardOutput = True
        .RedirectStandardError = True
    End With
    p.Start()

However, when I run this, it throughs an error during runtime and crashes on p.start()

Dim p As Process = New Process()
With p.StartInfo
    .WorkingDirectory = Environment.GetEnvironmentVariable("ProgramFiles") & "\rest_of_my_path\"
    .FileName = "myextprogram.exe"
    .Arguments = "-n Unnamed -f file.abc"
    .CreateNoWindow = True
    .UseShellExecute = False
    .RedirectStandardOutput = True
    .RedirectStandardError = True
End With
p.Start()

I tried adding spaces, quotation marks, just name it but ALWAYS getting an Exception has been thrown by the target of an invocation. I believe it's complaining about the path.

I'm almost sure it's simple but just cannot put my finger on it.

Any help is appreciated.

Это было полезно?

Решение

ok, found a fix...if anybody is interested...

Rather than having

.FileName = "myextprogram.exe"
.Arguments = "-n Unnamed -f file.abc"

I now have

.FileName = "cmd"
.Arguments = "myextprogram.exe -n Unnamed -f file.abc"

Everything is working as expected now.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top