Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

Passing c# command line arguments in a batch file

I have build a c# code which would basically take four arguments a1 a2 a3 a4. I am trying to make a batch file so that the user can enter his arguments and code gives the particular output. I am not sure how do i send these arguments to a batch file. i tried creating exe but it does not seem to work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To send arguments to a batch file, you do invoke it from the command line (or from another batch file) like this:

myfile.bat a1 a2 a3

Within the batch file, the arguments are represented by %1, %2, %3 (etc.), so within the batch file you would invoke your exe like this:

myapp.exe %1 %2 %3

That would pass the original arguments to the batch file, a1 a2 a3, along to the executable.

From within the executable you can access the arguments from your Main function

static void Main(string[] args)

The arguments, a1, a2, a3, would be in args[0], args[1] and args[2] respectively.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...