Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...