Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Running matlab in the linux background

510 views
Skip to first unread message

Siyanda Nazo

unread,
Apr 19, 2011, 4:02:02 AM4/19/11
to
Hi all

I am trying to run a matlab file on a remote host. I have an account on the machine and I can access the linux command line when I log in. The line I enter on the command line is:

nohup matlab -nojvm -r "My_script" > My_script_out.txt&

I have placed the 'exit' command at the end of the file 'My_script' but Matlab seems to go into a never ending loop and prints 'bad file descriptor' in the output file when it finishes executing the matlab script. The matlab file runs till completion but the problem is that my output textfile becomes large as a result of the continuous print of the 'bad file descriptor' line. After completion, this is what is printed in the file:'

>> Warning:
Connection to the X11 Display Server (localhost:10.0) has been lost. No more graphics windows can no longer be displayed in this session. Graphics Objects can still be printed, and all commands should still work. We recommend that you try to save your current session and exit
>> Bad file descriptor
Bad file descriptor
Bad file descriptor...

Has anyone encountered this problem and if so, what is the solution?

Håkon

unread,
May 4, 2011, 8:35:08 AM5/4/11
to
Hi,
I had the same problem. I am running Fedora 14,
MATLAB Version 7.12.0.635 (R2011a), and
> nohup --version
nohup (GNU coreutils) 8.5

I made a test scipt

function test()
for i=1:10
fprintf('line %d\n',i);
end
return

then issued
> nohup matlab -nodesktop -nosplash -r test 2>/dev/null 1>out.txt &

The file out.txt grew quite quickly into > 1GB fil (in some minute). Then I killed the job. And wrote
>tail -4 out.txt
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

Then I write:
>head -30 out.txt

< M A T L A B (R) >
Copyright 1984-2010 The MathWorks, Inc.
Version 7.12.0.635 (R2011a) 64-bit (glnxa64)
March 18, 2011


To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.

line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10
>> 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 reading character from command line
Warning: Error reading character from command line
Warning: Error reading character from command line

Then I changed the script to include "exit" at the end:
function test()
for i=1:10
fprintf('line %d\n',i);
end
exit
return

Now it work fine. The out.txt file now contains
>cat out.txt

< M A T L A B (R) >
Copyright 1984-2010 The MathWorks, Inc.
Version 7.12.0.635 (R2011a) 64-bit (glnxa64)
March 18, 2011


To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.

line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10

So for me, I seem to have a solution when I put "exit" at the end of the script...
Regards
Haakon Haegland

Benjamin

unread,
Dec 15, 2011, 12:22:08 PM12/15/11
to
It's because matlab does not like the & character. It thinks you are trying to access that program.

To fix, just wrap your script into a mini shell script:

nohup matlab -nojvm -r "My_Script"

execute it as

./myshellscript >> output.txt &

That should prevent matlab from throwing errors.

"Siyanda Nazo" wrote in message <iojfhq$6bn$1...@fred.mathworks.com>...
0 new messages