matlab在后台nohup运行时,循环输出Bad file descriptor和 Warning: “Error reading character from command line“问题解决

1、问题:

最近需要在远程跑Matlab代码,找来了一段后台运行命令:

nohup matlab -nodisplay -nosplash -r matlab_command > outfile.txt &

运行命令 matlab_command 后,将结果输出到 outfile.txt 中。但后来发现,当程序运行因错误中止时,之后的输出结果总会循环输出Bad file descriptor和 Warning: "Error reading character from command line" 这两条信息,使输出文件很大,占用空间,被管理员各种邮件警告了很多次,很是烦恼。

Warning: "Error reading character from command line" 
Warning: "Error reading character from command line" 
Warning: "Error reading character from command line" 
Warning: "Error reading character from command line" 
Warning: "Error reading character from command line" 
Warning: "Error reading character from command line" 
Warning: "Error readinBad file descriptor
Bad file descriptor
Bad file descriptor
Bad file descriptor
Bad file descriptor
Bad file descriptor
Bad file descriptor

2、解决方案:

(1)方案1:我首先找到了这篇博客

https://blog.csdn.net/sethinking/article/details/88375995

将matlab执行语句,改为执行相应文件的命令形式,即:

nohup matlab -nodisplay -nosplash <matlab_file.m> > outfile.txt &

但我相应的matlab文件中有很多内置的 function,这样去执行matlab代码会导致 function 识别不出来,运行不了,我还是希望能够通过执行命令行的方式,来运行文件。

(2)方案2:在 & 前加上 </dev/null

https://realwecan.blogspot.com/2013/10/infinite-error-loop-when-running-matlab.html

nohup matlab -nodisplay -r matlab_command > outfile.txt </dev/null &

使用了这个方案后,问题迎刃而解。但为什么可以成功,原博中没有细说,只是说引起这个问题的是字符 &。在这个字符前加上就可以解决这个问题了。如有懂得其中原理的朋友,希望能够不吝赐教。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BUGORFEATURE

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值