LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Can't seem to catch some output from a program - not stdout or stderr. uhh.. help? (https://www.linuxquestions.org/questions/programming-9/cant-seem-to-catch-some-output-from-a-program-not-stdout-or-stderr-uhh-help-785702/)

BrianK 01-29-2010 05:16 PM

Can't seem to catch some output from a program - not stdout or stderr. uhh.. help?
 
The program in question in Maya (by Autodesk).

I'm running a little test mel script that looks like so:

Code:

print "MEL -- PRINT CALL\n";
python("print 'PYTHON -- PRINT CALL. FROM MEL'");

when I run this little script from the command line (through maya), I see both print statements. However, if I try to redirect stdout and/or stderr to a file, I only get the first line via stderr & never see the second line. I'm doing my redirection like so:

maya -batch -script my_script 2> err
maya -batch -script my_script 1> out

Doing it that way, I see the first line in 'err' but don't see second in either.

Is there a way I can see how the second line is being printed?

BrianK 01-29-2010 06:50 PM

hmm... found that maya is stealing stdout & stderr, and doing it's own thing with them. Not sure if I can do what I'm after at all.

If anyone knows, feel free to post, otherwise, I'm calling it quits on this one.

ta0kira 01-30-2010 11:53 AM

I ran into something similar to this with MATLAB, where MATLAB would run over both 1 and 2 with whatever it felt like, so I wrote a wrapper that inserted a MATLAB command to open /proc/self/fd/3, then redirected 3 on the command-line. I gave it a name like script_out, and in the script I sent output there instead of standard output. This isn't MEL, but it should be obvious the correlation:
Code:

% prepended to the script:
script_out = fopen('/proc/self/fd/3', 'a');

When running the script:
Code:

matlab (some stuff to trick it into running a script) 3>&1 1>&2
In the body of the script:
Code:

fprintf(script_out, '%s\n', row_data(1:length(row_data)-1));
MATLAB doesn't recognize pre-opened file descriptors other than 1 and 2, but maybe Maya will let you use 3 without going through /proc.
Kevin Barry


All times are GMT -5. The time now is 04:56 PM.