如何在VB.net中调用的程序中传递多个命令行参数 [英] How to pass multiple command line arguments in a Program called in VB.net

查看:89
本文介绍了如何在VB.net中调用的程序中传递多个命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


您可能会在上面的代码中看到,我试图运行一个名为File_copy_program.exe的程序,该程序是使用C ++创建的.现在,该程序在Main中有3个参数(即程序名称,源文件,目标文件).


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

现在一行:p.Arguments ="D:\ c \ File_copy_program.exe"&"D:\ PE.nrg"&"D:\ c \ 1.nrg"

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

不起作用.我的程序说传递的参数数目无效(因为我有一个条件,如果参数数目不等于3,请确保程序中止).

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"

或者,如果使用变量:

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.

这篇关于如何在VB.net中调用的程序中传递多个命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆