PDA

View Full Version : echo system command output to screen


doppelganger
08-15-2003, 12:12 AM
Regards all,

I am using the system command to invoke a batch file to create backups of the projects folder on exit from Maya. The problem is that when this command executes it takes a long time to complete and gives no visual cue as to what is happening or what the status is. Is there a way to echo the output of this batch file to the screen? I tried having system run the NT command "cmd" to invoke the batch file instead of just giving system() the path (example "cmd c:\backup.bat" ) in the hopes this would open a command window but no such luck. The command simply runs then prints output to the script editor once it terminates.

Originally I attached a system call running xcopy to the quit application event in userSetup.mel using a scriptJob thereby removing the need for a second script to call or a batch file but this proved to be impractical due to the lack of feedback from the script and the time it takes to complete would fool almost any user into thinking Maya had crashed.

Any reccomendations?

Thanks,

Scott (Mel novice and wannabe future TD)

klod
08-15-2003, 09:19 AM
Hi Scott,

Hi had the same problem some times ago, and I solve it using a pipe:

global proc mySystemCommand(string $command)
{
print ($command + "\n");
$pipe = popen( $command, "r" );
while ( !feof( $pipe ) )
{
string $line = fgetline($pipe);
print $line;
}
pclose( $pipe );
}

The mySystemCommand works exactly the same as the maya system command.

That should help :)
Klod

alexx
08-16-2003, 07:55 PM
hey,

when adding a "start" in front of your system calls, a command window opens and it even runs seperated from maya itself..

i used that for similar purposes.

example:

system("start xcopy /e /s /q \\\\internet\\all\\*.* c:\\myBackup");

should open a command window and let you see what happens but you can continue to work in maya without waiting for the command to finish

and if you want to be able to see the result later, you can redirect the output to a file with the >> like that:

system("start xcopy /e /s /q \\\\internet\\all\\*.* c:\\myBackup >>c:\\mayaCopyLog.txt ");


cheers

alexx

doppelganger
08-17-2003, 07:01 AM
Thanks to you both for yout input. The combined advice has helped me allong quite a bit. This forum has proved invaluable once again!

Now I have a new problem. I create a userSetup.mel file with the following text

scriptJob -e "quitApplication" "system(\" start xcopy /d/e/y/i c:\\test c:\\test2 \")";

When I exit maya the command window says invalid number of parameters. I added the escaped quotes \" \" because the process wouldnt even run at all if I included it in the userSetup without them. Strangely if I run scriptjob from the command line in Maya it works without the quotes... but I digress from the real problem at hand.

if i declare a string with the command as such:

string $command = " start xcopy c:\\test c:\\test2 /d/e/y/i ";

scriptJob -e "quitApplication" "system($command)";

Then it runs fine. Can someone point out my logical or syntax error here... I would like to know why my original approach didn't work. It still looks like the same thing to be just substituting a variable for the same command.


Thanks

Scott

CGTalk Moderation
01-15-2006, 09:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.