user1642036
user1642036

Reputation: 195

Argument issue when using vb.net shell ()

I was trying to use shell function in vb.net to run a program and then write/export the result else where , it works on win8 but not XP !! The command line prints this error

'C:\Documents' is not recognized as an internal or external command, operable program or batch file. Press any key to continue . . .

Dim save as String="C:\exported.txt"
Dim command As String = tempPath & "app.exe -f " & IO.Path.GetTempPath & "  -o " & save & "  & pause"

shell("cmd /c " & command, AppWinStyle.NormalFocus, True)

Upvotes: 0

Views: 509

Answers (2)

simon at rcl
simon at rcl

Reputation: 7344

You hace a folder in the command with a space in it (probably the documents and Settings folder). cmd.exe has no way of telling whether the space is in the file name or the end of the file name, unless you put the file name in "" - like "C:\doxuments and Settings..."

Dim command As String = tempPath & "app.exe -f \"" & IO.Path.GetTempPath & "\"  -o \"" & save & "\"  & pause"

(\" is intended to escape a " so that it translates to embedding a " in the string. I'm not sure what the VB syntax is.)

EDIT:

I think @Roy van der Velde below has the 'escaping correct. The final part not checked is tempPath. See my comment on the question.

Upvotes: 0

Roy van der Velde
Roy van der Velde

Reputation: 220

    Process.Start(IO.Path.Combine(tempPath, "app.exe"), "-f """ & IO.Path.GetTempPath & """  -o """ & Save() & """  & pause")

Upvotes: 1

Related Questions