필터 지우기
필터 지우기

clean up standard output when running in background

조회 수: 6 (최근 30일)
pfb
pfb 2014년 10월 20일
댓글: pfb 2015년 4월 14일

Hi all,

I often run matlab in background, by issuing the following command in linux or mac OS (bash)

nohup matlab -nodesktop -nosplash -nodisplay -nojvm < code.m &> out.txt &

This launches the script code.m in a background instance of matlab and redirects the relevant standard output and standard error into out.txt.

The latter file contains a couple of features I'd like to get rid of

1) the matlab "textual splash screen" (the one appearing in the command window when launching matlab in interactive graphical mode)

2) a variable number of consecutive instances of the prompt ">>".

For instance the following code

fprintf('\n\n\n\n');
a=1;
fprintf('hello\n');
b=2;
warning('whoa');
c = 3;
fprintf('\n\n\n\n');
fprintf('%d\n',c);
for j=1:3
    fprintf('%d %d\n',j,c*j);    
end
error('hey!!');
exit;

produces the following output

                                < M A T L A B (R) >
                      Copyright 1984-2010 The MathWorks, Inc.
                    Version 7.12.0.635 (R2011a) 64-bit (maci64)
                                   March 18, 2011
      To get started, type one of these: helpwin, helpdesk, or demo.
      For product information, visit www.mathworks.com.
>> 
>> >> hello
>> >> Warning: whoa 
>> >> 
>> 3
>> 1 3
2 6
3 9
>> ??? hey!!
>> >> 

I'd like to get rid of the "splash screen", although I can live with it.

What I find really annoying is the apparently random appearance of the prompts ">>". With more complex codes much longer sequences of ">>" appear.

I know I could print my output in some output file, instead of the stdout. But getting rid of all the above stuff would simplify my life.

Anyone has any idea of why I'm getting these ">>" and how can I get rid of them?

Thanks a lot for any help

Francesco

UPDATE

- I tried placing clc before the first fprintf, but had no effect;

- The same "problem" affects the most recent version of matlab I've got, i.e. matlab R2014b

답변 (1개)

Titus Edelhofer
Titus Edelhofer 2015년 4월 14일
Hi Francesco,
have you tried to use the diary function instead of redirection of output?
doc diary
I'm not sure, but it should not print out the command prompt, if I remember correctly ...
Titus
  댓글 수: 1
pfb
pfb 2015년 4월 14일
Hi Titus,
thanks for the suggestion. I never used this function.
From a quick look it produces a formatted output, but I might be wrong.
I am fine with the redirected standard output, except for the first few lines, which are affected by the ">>" problem.
Actually, that's not a big deal either, but I was curious on whether it can be fixed somehow.
Anyway I'll look further into diary and experiment a bit.
Cheers
Francesco

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by