1

Before you answer, I'm not looking for the functionality of ; to suppress command line printing.

I have a set of scripts which are not mine and I do not have the ability to change. However, in my scripts I make a call to these other scripts through evalin('base', 'scriptName'). Unfortunately, these other scripts do a lot of unnecessary and ugly printing to the command window that I don't want to see. Without being able to edit these other scripts, I would like a way to suppress output to the command line for the time that these other scripts are executing.

One potential answer was to use evalc, but when I try evalc(evalin('base', 'scriptName')) MATLAB throws an error complaining that it cannot execute a script as a function. I'm hoping there's something like the ability to disable command window printing or else redirecting all output to some null file much like /dev/null in unix.

Mohsen Nosratinia
  • 9,844
  • 1
  • 27
  • 52
zephyr
  • 2,182
  • 3
  • 29
  • 51
  • How are the scripts outputting to the command window? Lack of `;`? `disp`? `fprintf`? Why can't you edit the scripts? – sco1 Apr 06 '16 at 13:52
  • They generally use `fprintf`. I cannot edit the scripts because they're not mine and I don't have access to them. I can only run them. – zephyr Apr 06 '16 at 14:00
  • You *could* [overload `fprintf`](http://stackoverflow.com/a/3029833/2748311) to do nothing, but this is not a good solution. You are better off fixing the files yourself. You'd also be much better off refactoring these scripts into functions so you pass them arguments explicitly rather than relying on `evalin` to function correctly. – sco1 Apr 06 '16 at 14:03
  • @excaza As I said, I don't have permissions to edit the files. I can only run them. However your solution to overload fprintf, while horrible practice, is the only valid solution I can find. If you write an answer, I'll accept it. – zephyr Apr 06 '16 at 15:33

3 Answers3

1

I think you just need to turn the argument in your evalc example into a string:

evalc('evalin(''base'', ''scriptName'')');
Mohsen Nosratinia
  • 9,844
  • 1
  • 27
  • 52
  • You are absolutely correct. I feel dumb for not having realized that before. This solution has worked! – zephyr Apr 07 '16 at 15:19
0

Have you tried this solution here ?

echo off;
Sameh K. Mohamed
  • 2,323
  • 4
  • 29
  • 55
  • 2
    `echo` is not on by default, and if it was on it would be printing every command executed, which doesn't seem like the case here. – sco1 Apr 06 '16 at 13:57
  • I found that as well but it does not apply to my situation. `echo` being on simply prints all executed commands to the command window. Having that off turns off that "feature" but actual prints to the command window still occur. `echo` is unrelated to my question. – zephyr Apr 06 '16 at 14:03
0

I don't know if it will fit your needs, but another solution can be to open a new session of Matlab, and use there only minimized -nodesktop form (-just the command window). You can run from there the annoying scripts, and work on the main session as usual.

The problem here is that the sessions can't be synchronized, so if you need to work with the results of the scripts all the time, it'll be a little bit complicated. Maybe you can save the result to disk, than call it from the main session... But it mainly depends on your workflow with those scripts.

Adiel
  • 3,071
  • 15
  • 21