0

我有一个来自 Visual Compaq 编译器的 .exe 文件。我要运行,我必须从键盘给它一些变量,例如输入路径、带参数的文件名、输出路径等

我想编写一个批处理文件以多次运行 exe,但我不知道如何使 exe 文件直接从批处理文件中读取输入,以避免自己一直从 keeboard 提供输入。

非常感谢

4

3 回答 3

1

尝试这个:

@echo off
>input.txt echo input line 1
>>input.txt echo input line 2
>>input.txt echo input line 3
>>input.txt echo input line 4
exefile.exe <input.txt

或者,对一堆 ECHO 使用带有单个重定向的语法,但)输入行中的所有字符也需要转义:

@echo off
>input.txt (
echo input line 1
echo input line 2
echo input line 3
echo input line 4
)
exefile.exe <input.txt

如果这不起作用,请尝试

type input.txt | exefile.exe

如果这些都不起作用,那么您的 exe 文件不接受 STDIN 输入。

如果它确实有效,那么批处理文件可以帮助启动多次运行。

于 2013-06-10T09:30:44.980 回答
0

If your Batch file is used just to execute several times the .exe file and does not contain Batch logic, then you can directly place all the keyboard input in a file (that may have any extension, like .txt) and feed the file into cmd.exe. This trick makes the creation of the file much simpler, because it does not require multiple redirections nor echo commands. For example:

commandFile.txt:

echo off
rem Execute first run:
exefile.exe
first run input line 1
first run input line 2
END
rem Execute second run:
exefile.exe
second run input line 1
second run input line 2
END
rem Terminate the cmd.exe session
exit

To "execute" previous file, enter this:

cmd < commandFile.txt
于 2013-06-10T16:27:50.897 回答
0

您可能会逃脱管道运营商。如果您在 cmd 行中键入“dir > dir.txt”,它将重定向,或者将输出通过管道传输到文件而不是标准输出。同样,您可以使用另一个符号“<”来从文件中管道输入,而不是键盘。

在这里,这是我在广告中断期间敲出的一个快速示例。

1.C源

#include <cstdio>

int main()
{
    int numPairs, num1, num2, result;
    int curPairIndex;

    printf("Enter number of pairs to add: ");
    scanf("%d", &numPairs);
    printf("\n");
    for (curPairIndex=0; curPairIndex<numPairs; curPairIndex++)
    {
        scanf("%d %d", &num1, &num2);
        printf("%02d. %d + %d = %d\n", curPairIndex, num1, num2, num1+num2);
    }

    return 0;
}

2.sampleInput.txt

3
3   4
10  20
100 1000

3. 示例命令行命令

001-forumSample < sampleInput.txt > sampleOutput.txt

4. 样本输出.txt

Enter number of pairs to add: 
00. 3 + 4 = 7
01. 10 + 20 = 30
02. 100 + 1000 = 1100
于 2013-06-10T09:36:00.510 回答