0

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).

2
  • You might be missing spaces inside your string, between the arguments. Can you check how many arguments it's actualy seeing, by putting a breakpoint and checking the exception it throws. Commented Aug 1, 2010 at 17:46
  • 1
    Arguements should not have the the program in it. Commented Aug 1, 2010 at 18:13

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@Henk Holterman - fair enough. I thought that with the first example that was clear enough, but possibly not to everyone. Added more information to answer.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.