您如何 运行 来自 Windows cmd 的可执行文件并向其传递参数参数和文件输入重定向?

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

我成功了 运行 我从 Windows 命令行用 一个整数参数或一个重定向以指定来自 .txt 文件的输入。有什么办法可以同时做到吗?

例如,Linux 中的同一项目接受“./a.out 1 < testfile.txt”,因此 1 在 arg 数组中,testfile.txt 被重定向为输入。 Windows 中的相同输入将不起作用。我试过类似 ./a.exe (1 & '< testfile.txt') 的方法,但没有成功。

感谢您提供的所有有用回复, 泰勒

尝试组合 type command and pipe.

类似于:

type testfile.txt | a.exe 11

您可能需要调整一下。无法在 linux 上进行测试:]

这行不通:

a.exe 1< testfile.txt

因为 1< 被解释为 "redirect standard handle #1"。对于大多数应用程序,这将有效:

a.exe 1 < testfile.txt

(注意额外的 space!)

如果您的特定应用程序因额外 space 而阻塞,并且由于某种原因您无法修复它,这是另一种选择:

<testfile.txt a.exe 1