Linux:.sh 脚本中的程序没有输出

标签 linux bash shell

我正在尝试在 Linux 中执行 Windows 程序,并且我想从该进程中获取输出 (stdout)。我将此文本放入 .sh 文件中: wine Blockland.exe ptlaaxobimwroe -dedicated -port 30000 >> consoleLog.txt 它执行了程序,但创建了一个空白文件。在终端窗口中直接执行时,此命令始终有效。那么为什么在 .sh 脚本中不将输出打印到文件中呢?

最佳答案

它可能正在将输出发送到 stderr。为了解释这种可能性,尝试

wine Blockland.exe ptlaaxobimwroe -dedicated -port 30000 2>&1 >>consoleLog.txt

2>&1 位将 stderr(文件描述符 2)重定向到 stdout(文件描述符 1)。然后它将 stdout(现在包括 stderr 输出)重定向到您的日志文件。

关于Linux:.sh 脚本中的程序没有输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17847852/

相关文章:

linux - 错误 : Could not run command from prerun_command: Execution of '/etc/puppet/etckeeper-commit-pre' returned 1:

java - Runtime.getRuntime().exec() 不执行某些命令

linux - linux命令的内部工作

perl - 将 "file name"从文本文件传递到命令行,其中文件的每一行都是文件名

linux - Shell 脚本在 Ubuntu 中成功但在 Amazon Linux 2 中失败?

linux - Linux 上的第一个 top 命令结果可信吗?

shell - awk 捕捉文本进入下一行

linux - 无法在 Centos 6 上安装 jpegoptim

algorithm - 通过标志组值平滑地分割成固定序列

bash - 使用 bash 检查一行是否为空