0

当从命令行运行“csc”命令时,它会生成 .exe 文件,然后我们必须运行该 .exe 文件来生成输出。

我需要的是我想通过在一行中提供输入文件来获得输出。

例如: 通常的方式

csc sample_add.cs

上述命令生成 sample_add.exe

示例_add.exe 4 5

输出:4和5相加是9

我想写一行以获得最终输出。

“任何命令” sample_add.cs

输出:4和5相加是9

4

2 回答 2

1

没有创建批处理文件,真的没有办法让 csc.exe 做到这一点。但是,您可能想查看ScriptCS

于 2013-11-15T05:35:35.077 回答
0

在批处理文件中执行问题中给出的示例可能如下所示:

@echo off
rem %1 = CS source file
rem %2 = Number 1
rem %3 = Number 2

set SourceFile=%1
set ExeFile=%SourceFile:.cs=.exe%

csc %SourceFile%
if errorlevel 1 ...  <<<-- do error handling here.
                         Sorry, i don't know the exit codes of csc :(

if not errorlevel 1 %ExeFile% %2 %3
于 2013-11-15T11:01:49.983 回答