我们有一个Groovy脚本与一个退出status的0时候一切工作和non-0 status针对不同类型的故障条件.例如,如果脚本了用户和一个电子邮件地址作为参数,它将与一个退出status的1为无效的用户,和status的2为无效的电子邮件地址格式.我们用System.exit(statusCode)它.这工作正常,但使脚本难以编写测试用例.
在测试中,我们创建我们的GroovyShell,创建我们的Binding和调用shell.run(script,args).对于断言失败条件的测试,System.exit()导致JVM(和测试)退出.
是否有使用System.exit()退出Groovy脚本的替代方法?我尝试抛出未捕获的异常,但是使输出变得混乱,并且始终使状态代码为1.
在我们的测试用例中,我还尝试使用System.metaClass.static.invokeMethod更改System.exit()不退出JVM 的行为,但这似乎是一个丑陋的黑客.
在下面提供的示例中,我执行nmake然后将STDOUT/STDERR重定向到tee,然后将其发送到屏幕,还发送到日志文件.问题是我正在尝试捕获nmake的退出代码而不是tee.我需要的是nmake的退出代码,而不是tee.
nmake | tee output.txt
Run Code Online (Sandbox Code Playgroud) 我正在修改一些我没有写过的Fortran代码,而且我自己没有很多的经验.我刚刚发现了一些情况,其中一些格式错误的输入被默默地忽略,并且想要更改该代码以做更合适的事情.如果这是C,那么我会做类似的事情
fprintf(stderr, "There was an error of kind foo");
exit(EXIT_FAILURE);
Run Code Online (Sandbox Code Playgroud)
但在fortran中,我知道如何做的最好看起来像
write(*,*) 'There was an error of kind foo'
stop
Run Code Online (Sandbox Code Playgroud)
缺乏输出流(次要问题)和退出状态(主要问题)的选择.
如何终止具有非零退出状态的fortran程序?
如果这是依赖于编译器的,那么与gfortran一起使用的解决方案会很好.
所以我现在将STS安装到我的Windows 7 64位机器上,每次我尝试运行STS时,我都会在下面找到附加的Java退出代码= 13错误.
我没有将Eclipse安装到我的机器中,我提到这是因为每次我尝试使用Google时,这个错误代码线程都会出现关于Eclipse上发生的同样问题.
我也试过检查我的机器上是否安装了Java.
有谁知道如何解决这个问题?
如何从PowerShell写入stderr,或者捕获这样的错误
这些年来,我throw通过错误或写作经历幸存下来Write-Error,但我已经厌倦了,而且在我的脚本中我只想看到一条简洁的错误信息.我一直在努力的每个组合trap,throw,Write-Error,和-ErrorAction,但无济于事:
try {
throw "error" # Sample code for a stack overflow. In the theater
# of your mind, imagine there is code here that does something real and useful
} catch {
Write-Error "An error occurred attempting to 'do something.' Have you tried rebooting?"
}
Run Code Online (Sandbox Code Playgroud)
这是我想看到的用户体验:
C:\> & .\Do-Something.ps1
An error occurred attempting to 'do something.' Have you tried rebooting?
C:\> ?
Run Code Online (Sandbox Code Playgroud)
相反,我得到:
C:\> …Run Code Online (Sandbox Code Playgroud) 是否有退出代码列表和Java进程终止的含义?因为我有一个退出代码23,我不知道它是什么(我无法更改日志以查看完整的堆栈跟踪,因为它位于不同的远程服务器).
我浏览了几个小时,找不到退出代码23.
我试图在bash shell中并行运行3个命令:
$ (first command) & (second command) & (third command) & wait
Run Code Online (Sandbox Code Playgroud)
这个问题是,如果first command失败,例如,退出代码是0(我猜因为wait成功).
期望的行为是,如果其中一个命令失败,退出代码将为非零(理想情况下,其他正在运行的命令将被停止).
我怎么能实现这个目标?
请注意,我想并行运行命令!
我正在编写一个c ++程序,它执行并输出(实时)shell脚本,makefile或其他程序.但是,当有错误或没有错误时,我希望我的程序返回不同.
#include "execxi.h"
using namespace std;
int execXI::run(string command)
{
FILE *in;
char buff[512];
// is this the check for command execution exited with not 0?
if(!(in = popen(command.c_str(), "r"))){
// I want to return the exit code and error message too if any
return 1;
}
// this part echoes the output of the command that's executed
while(fgets(buff, sizeof(buff), in)!=NULL){
cout << buff;
}
pclose(in);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
是我到目前为止.
假设这个脚本运行make来构建一个程序,它给出了一个错误
on_target_webkit_version out/Release/obj/gen/webkit_version.h
Traceback (most recent call …Run Code Online (Sandbox Code Playgroud) 这个自我回答的问题试图解决在 PowerShell中处理进程退出代码的两个不同方面:
在 PowerShell 代码中,如何查询外部进程设置的退出代码(对外部程序的调用),这些退出代码如何与 PowerShell 的错误处理相结合?
当其他人通过其 CLI pwsh(PowerShell Core)/ powershell.exe(Windows PowerShell)调用 PowerShell 时,什么决定了 PowerShell 进程的退出代码,该代码将成功与失败传达给调用进程(可能是构建/CI/自动化服务器任务) ,计划任务或不同的外壳,例如)。
我有一个简单的Windows批处理命令(robocopy)返回零错误,但在Jenkins中始终标记为失败.我想知道为什么?
D:\ Jenkins\jobs\Jenkins Config Backup\workspace> exit 1构建步骤'执行Windows批处理命令'将构建标记为失败完成:FAILURE