0

We have a C# console application, which takes various input(note- no command line input)

Eg C:\MyTool.exe

Enter Option (1-4):

Enter Location(1-7):

Enter Region (1-3):

After providing these input one by one, tool process the input and produce some business result.

Now, I have a requirement to run these tool every hour with Option -1, Location -2, Region-1

What I am planning to do is to setup the Windows Schedular, which will call these EXE, but the problem is how can I provide the input which in may case (1, 2, 1) respectively to the console tool.

I am thinking is there is any way that I can provide the input upfront in the command line itself...

Eg C:\MyTool.exe << 1 2 1 So that I can create batch file of these command and schedule it accordingly.

Please suggest.

Thanks, Siraj

  • Likely you'll need to put the input into a file, and then do input direction from that file into your command: `MyToolInput.txt > MyTool`, however cmd's input & output redirection support is pretty limited: you'll need to try a few things from the command line before trying under the scheduler. Remember the scheduler can run a batch file: makes it much to define non-trivial commands than the task scheduler UI. – Richard May 28 '16 at 07:36
  • 1
    Why not changing the program to accept one optional command line argument directing to a (xml, json, txt) file? – Jeroen Heier May 28 '16 at 07:49
  • no change in the code – Mohammed Sirajuddin May 28 '16 at 08:03

1 Answers1

0

Create an input file where the input options are separated by CRLF (carriage return, Line feed). For example, open a command prompt and go to the folder where your MyTool.exe is located. Then type: 'copy con input.txt<enter>1<enter>2<enter>1<enter><F6>' This will create the input file. Now use 'MyTool < input.txt'. This will run your tool with accepting these input parameters. This command can be used in the task scheduler.

Ton Plooij
  • 2,583
  • 12
  • 15
  • Hi Ton, I want to have Ctrl+C in my input.txt. One of the input for the tool could be this Ctrl+C. Please suggest. – Mohammed Sirajuddin Jun 21 '16 at 11:51
  • You can't do that through the input.txt file. Some possible solutions ar listed here: http://stackoverflow.com/questions/813086/can-i-send-a-ctrl-c-sigint-to-an-application-on-windows – Ton Plooij Jun 21 '16 at 19:39