如何将nohup输出重定向到指定文件?

编程入门 行业动态 更新时间:2024-10-19 20:26:19
本文介绍了如何将nohup输出重定向到指定文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在SO上发现的其他示例中尝试的所有内容似乎都不起作用.我试图使用nohup运行我的应用程序,但将应用程序的输出附加到文件中.

Everything I have tried from other examples I have found on SO don't seem to work. I am trying to run my application using nohup but append the output of the application to a file.

我尝试了以下一些方法.似乎都不起作用.

I have tried some of the following. None of which seem to work.

nohup dotnet application.dll &> out.log & nohup dotnet application.dll > out.log 2>&1 & nohup dotnet application.dll > /opt/out.log &

我总是收到类似的东西

-bash: out.log: Permission denied

我尝试使用sudo运行该应用程序,但它似乎仍然无法正常工作.

I have tried running the application using sudo but it still doesn't seem to work.

nohup dotnet application.dll &

效果很好,但是它将输出定向到其他目录,例如/home/ubuntu/nohup.out

Works fine, but it directs the output to some other directory like /home/ubuntu/nohup.out

我在做什么错了?

推荐答案

nohup dotnet application.dll>out.log 2>& 1& 是正确的格式.

>out.log 将STDOUT重定向到文件 out.log .

> out.log redirects STDOUT to the file out.log.

2>& 1 将fd2(STDERR)重定向到fd1(STDOUT),该文件已经重定向到文件 out.log .

2>&1 redirects fd2 (STDERR) to fd1 (STDOUT), which is already redirected to the file out.log.

您的问题出在文件权限(或只读文件系统)上.在命令前面加上 sudo 不能解决此问题,因为 sudo 仅以root身份执行 nohup dotnet application.dll ,因此输出重定向为由bash使用您的普通用户权限来完成.您可以通过使用root特权调用单独的shell来解决此问题:

Your problem lies in the file permissions (or a read-only filesystem). Prepending sudo to your command can't fix this, because only nohup dotnet application.dll is executed as root by sudo, the output redirection is done by bash with your normal user privileges. You can work around this by calling a separate shell with root privileges:

sudo sh -c 'nohup dotnet application.dll > out.log 2>&1 &'

更多推荐

如何将nohup输出重定向到指定文件?

本文发布于:2023-07-06 07:35:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047373.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   重定向   文件   nohup

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!