Ty Deuty
Ty Deuty

Reputation: 137

How can you run an executable from Windows cmd and pass it both a argument parameter and redirection for file input?

I have success running a program I wrote (with file extension .exe) from the Windows command line with either an integer parameter or a redirection to specify input from a .txt file. Is there any way to do both?

For instance, the same project in Linux accepts './a.out 1 < testfile.txt' so 1 is in the arg array and testfile.txt is redirected as input. The same input in Windows will not work. I have tried something like ./a.exe (1 & '< testfile.txt') with no luck.

Thank you for any and all helpful responses, Tyler

Upvotes: 0

Views: 1813

Answers (2)

Harry Johnston
Harry Johnston

Reputation: 36308

This won't work:

a.exe 1< testfile.txt

because 1< is interpreted as "redirect standard handle #1". For most applications, this will work:

a.exe 1 < testfile.txt

(note the extra space!)

If your particular application chokes on the extra space, and for some reason you can't fix that, this is another option:

<testfile.txt a.exe 1

Upvotes: 2

Kupto
Kupto

Reputation: 2992

Try combining type command and pipe.

something like:

type testfile.txt | a.exe 11

You might have to tweek that. Can't test it here on linux :]

Upvotes: 0

Related Questions