rlwrap 在后台运行时挂起作业

发布于 2024-09-24 20:55:09 字数 677 浏览 1 评论 0原文

我对 rlwrap 有疑问(请参阅手册页此处)。考虑这种情况:empty.tcl 是一个空文件。在 bash 中,这一行

tclshempty.tcl &

在后台运行作业并退出,因此我得到此提示

[1]+ Done tclshempty.tcl

虽然此行

rlwrap tclshempty.tcl &

在后台运行作业并且不会退出它,所以我收到此提示

[1]+ Stopped rlwrap tclshempty.tcl.

相应的作业挂在后台。我的问题是如何让它退出工作而不是挂起?

rlwrap 是一个 Linux 实用程序命令,它运行指定的命令,拦截用户输入以提供 readline 的行编辑、持久历史记录和完成。正如那里提到的,rlwrap 的主要属性是你不应该注意到命令和 rlwrap 命令之间的任何区别,但是,正如上面所描述的,这个属性不成立。

也许有人可以建议 rlwrap 的替代方案,其功能符合预期?

I have a problem with rlwrap (see the man page here). Consider this situation: empty.tcl is an empty file. At bash this line

tclsh empty.tcl &

runs the job in the background and exits it, so i get this prompt

[1]+ Done tclsh empty.tcl.

While this line

rlwrap tclsh empty.tcl &

runs the job in the background and doesn't exit it, so i get this prompt

[1]+ Stopped rlwrap tclsh empty.tcl.

The corresponding job hangs at the background. My question is how to make it exit the job rather then hang?

rlwrap is a Linux utility command which runs the specified command, intercepting user input in order to provide readline’s line editing, persistent history and completion. As it is mentioned there, the main property of rlwrap is you shouldn’t notice any difference between command and rlwrap command, however, as it is described above, this property doesn't hold.

Maybe one can suggest an alternative for rlwrap which functions as expected?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一江春梦 2024-10-01 20:55:09

基本上,你不能做到这一点并让它发挥作用。问题(从您的角度来看)是,如果您将脚本文件参数传递给 tclsh,它将执行它然后退出。可以使用不带任何其他参数的 rlwrap tclsh(因此它可以在交互模式下工作),也可以使用模拟 Tcl 交互 REPL 的脚本。写起来并不太难:

fconfigure stdout -buffering none
set command ""
puts -nonewline "% "
while {[gets stdin line] >= 0} {
    append command $line "\n"
    if {[info complete $command]} {
        # Got a complete command; evaluate and catch result
        if {[catch $command msg]} {
            puts "error: $msg"
        } elseif {$msg ne ""} {
            puts $msg
        }
        set command ""
        puts -nonewline "% "
    }
}

好吧,你可以稍微调整一下,但它展示了如何做到这一点。将其放在 real 脚本的末尾,rlwrap 应该可以很好地处理结果。

Basically, you can't do this and have it work. The problem (from your perspective) is that if you pass a script file argument to tclsh, it will execute it and then exit. Either use rlwrap tclsh with no further arguments (so it works in interactive mode) or use a script that emulates Tcl's interactive REPL. That's not too hard to write:

fconfigure stdout -buffering none
set command ""
puts -nonewline "% "
while {[gets stdin line] >= 0} {
    append command $line "\n"
    if {[info complete $command]} {
        # Got a complete command; evaluate and catch result
        if {[catch $command msg]} {
            puts "error: $msg"
        } elseif {$msg ne ""} {
            puts $msg
        }
        set command ""
        puts -nonewline "% "
    }
}

OK, you could tweak it a bit more, but it shows how to do it. Stick it at the end of your real script and rlwrap should cope just fine with the result.

め七分饶幸 2024-10-01 20:55:09

我在 bash 中遇到了类似的问题, rlwrap bash ./t.sh & ,通过转义 & 解决了这个问题, rlwrap bash ./t.sh \&

这在这里不好,它会过去的。作为输入参数。

I got similar issue in bash, rlwrap bash ./t.sh & , solved that by escaping &, rlwrap bash ./t.sh \&.

That is not good here, it will pass & as an input param.

浪荡不羁 2024-10-01 20:55:09

任何在后台运行的命令在尝试从 stdin(标准输入)读取时都会收到 SIGTTY(尝试 tclsh &)。 rlwrap 将始终从标准输入读取,即使 rlwrapped 命令不读取也是如此。严格来说,原发者的说法是正确的,这打破了 rlwrap 所谓的透明度,

这是一个严重的问题吗?我不这么认为 - rlwrap 当然只对从 stdin 读取的命令有用,无论有没有 rlwrap

Hans Lub(rlwrap 作者) 在后台运行这些命令都是没有意义的)

Any command that is run in the background will get a SIGTTY as soon as it tries to read from stdin (standard input) (try tclsh &). rlwrap will always read from stdin, even when the rlwrapped command doesn't. Strictly speaking, the original poster is right in saying that this breaks rlwrap's purported transparency

Is this a serious problem? I don't think so - rlwrap is of course only useful for commands that read from stdin anyway, and there is no point in running those commands in the background, with or without rlwrap

Hans Lub (rlwrap author)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文