【发布时间】:2020-07-29 16:31:00
【问题描述】:
我正在编写一个循环脚本来生成一个测试用例,在该测试用例中我对 ACM 问题的解决方案将失败。基本上它会无限生成随机测试用例文件,并使用我在网上找到的正确程序以及有问题的程序来解决它。然后对它们进行文件比较。
我之前在 Linux 上为此任务编写了一个脚本,它运行良好:
problem=383077-E
g++ rand.cpp -o rand.out
g++ std.cpp -o std.out
g++ $problem.cpp -o $problem.out
while true; do
./rand.out
./std.out < input.txt > answer.txt
./$problem.out < input.txt > output.txt
diff -s answer.txt output.txt
if [ $? -ne 0 ]; then
break
fi
done
然后我尝试为 Windows 编写一个 powershell 版本:
$problem = "383077-E"
g++ rand.cpp -o rand.exe
g++ std.cpp -o std.exe
g++ "$problem.cpp" -o "$problem.exe"
while ($true) {
.\rand.exe
cat input.txt | .\std.exe > answer.txt
cat input.txt | ".\$problem.exe" > output.txt # Error here
if (diff (cat file1) (cat file2)) {
break
}
}
我无法让这条线 cat input.txt | ".\$problem.exe" > output.txt 工作。
我是否使用了错误的工具(管道)来实现我的目标?
编辑:
目前我正在使用.cmd 脚本来兼容 Windows 7 环境:
@echo off
set problem=383077-E
g++ rand.cpp -o rand.exe
g++ std.cpp -o std.exe
g++ %problem%.cpp -o %problem%.exe
:loop
rand.exe > input.txt
std.exe < input.txt > answer.txt
%problem%.exe < input.txt > output.txt
fc answer.txt output.txt
if not errorlevel 1 goto loop
但我仍在寻找可以继续使用的 PowerShell 版本。
【问题讨论】:
标签: powershell