英文:
Makefile execution steps does not print in terminal if file is executed from a tcl file
问题
proc buildMirus { } {
exec ./autogrn.sh
if { [catch { exec make -j 6 }] } { /* make should give execution steps on terminal but it's not happening*/
puts "Error occurred while building"
}
}
英文:
proc buildMirus { } {
exec ./autogrn.sh
if { [catch { exec make -j 6 }] } { /* make should give execution steps on terminal but it's not happening*/
puts "Error occured while building"
}
}
答案1
得分: 2
Tcl的exec
命令默认将子进程的stdout
用作exec
的正常结果,并将子进程的stderr
用作exec
抛出的错误消息(如果存在)。这对许多用途非常方便,但不适用于您在这里的需求,您希望将输入和输出直接传递给用户,只处理任何错误代码。您可以通过添加一些重定向来实现这一点,具体如下:
if { [catch { exec make -j 6 <@stdin >@stdout 2>@stderr }] } {
<@stdin
表示“从stdin
通道获取输入”,>@stdout
表示“将正常输出发送到stdout
通道”,2>@stderr
表示“将错误输出发送到stderr
通道”。
英文:
Tcl's exec
command defaults to consuming the stdout
of the subprocess to be the normal result of the exec
, and to consuming the stderr
of the subprocess to be the message of an error thrown by exec
(if it exists). This is very convenient for many uses, but not what you want here, where you want to let the input and output go directly from/to the user and just handle any error codes. You can do this by adding some redirects, specifically:
if { [catch { exec make -j 6 <@stdin >@stdout 2>@stderr }] } {
<@stdin
says "take input from the stdin
channel", >@stdout
says "send normal output to the stdout
channel", and 2>@stderr
says "send error output to the stderr
channel".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论