开发者

How to pass multiple command line arguments in a Program called in VB.net

开发者 https://www.devze.com 2023-01-09 14:27 出处:网络
开发者_如何学Go Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

开发者_如何学Go
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim p As New ProcessStartInfo
p.FileName = "D:\c\File_copy_program.exe"
p.Arguments = "D:\c\File_copy_program.exe" & "D:\PE.nrg" & "D:\c\1.nrg"
p.WindowStyle = ProcessWindowStyle.Hidden
Process.Start(p)

End Sub

As you may see in the Above Code i am trying to run a program called File_copy_program.exe, which i created using C++. Now this program takes 3 Arguments in Main (i.e. program name, source file, target file).

Now the line: p.Arguments = "D:\c\File_copy_program.exe" & "D:\PE.nrg" & "D:\c\1.nrg"

is not working. And my program says invalid number of arguments passed (since i have a condition in it to make sure the program aborts if number of arguments are not equal to 3).


You need to pass in the arguments as you would pass them to the program on the command line:

p.Arguments = "D:\PE.nrg D:\c\1.nrg"

Or, if using variables:

p.Arguments = arg1string & " " & arg2string

As you can see from the first example, you don't pass in the program name as an argument, the same way that you would not follow the program name with itself again on the command line.


Try p.Arguments = "D:\PE.nrg" & " " & "D:\c\1.nrg" - it's doubtful you need to specify the application name as it'll be passed through automagically by DOS, and you need a space between your parameters.

0

精彩评论

暂无评论...
验证码 换一张
取 消