Rush Logo Rush Submit and Render Scripts
V 103.08 06/15/16
(C) Copyright 2008, 2015 Seriss Corporation. All rights reserved.
(C) Copyright 1995,2000 Greg Ercolano. All rights reserved.

   Submit/Render Scripts  

     Submit/Render Scripts 
    Simple Maya Submit/Render Scripts
    These are simple examples to run Maya's 'render' command through Rush.     
    These self contained scripts act as both a submit and render script.


    Advanced Maya Submit/Render Scripts That Autostart Irush
    These are slightly more complex examples that read back the jobid     
    from a submitted job, and automatically bring up Irush.


  Simple Submit/Render Scripts

    Here are some simple examples of submitting a Maya 'Render' command in various scripting languages.

    Here is the simple Maya render script written in Csh; it doesn't try to do anything fancy, it just submits the job and starts it rendering, without popping up irush.

    It's important to put your scripts on your file server, and to invoke the script with an absolute path, because the script will submit itself with that path, so the path must be resolvable on all machines that will be rendering.

    Here's the Csh script:

      Csh Simple Maya Submit/Render Script
      #!/bin/csh -f
      
      # SUBMIT THE JOB IF NO ARGS SPECIFIED
      if ( "$1" == "" ) then
          if ( $?RUSH_ISDAEMON ) exit 1                           # Prevent 'network worm' style recursion
      
          set scene  = "//server/scenes/foo.ma"                   # CHANGE THIS: scene file to render
          set logdir = "$scene.log"                               # log directory based on scene pathname
             
          if ( ! -d $logdir ) mkdir -m 0777 $logdir               # create log directory if none
      
          # Submit the job
          rush -submit << EOF
          title       SHOW/SHOT
          ram         250
          frames      1-10
          logdir      $logdir
          command     csh $0 -render $scene
          cpus        +any=5@1
      EOF
          if ( $status != 0 ) exit 1                              # Submit Failed
          exit 0                                                  # Submit OK
      endif
      
      # RENDERING ON REMOTE MACHINE?
      if ( "$1" == "-render" ) then
          echo "--- Working on frame $RUSH_FRAME"
          set cmd = "Render -s $RUSH_FRAME -e $RUSH_FRAME $2"     # command to run, $2 is scene
          echo "--- Executing: $cmd"                              # print what we're executing
          $cmd                                                    # run the command..
          set err = $status                                       # ..get exit code
          if ( $err != 0 ) then
              echo "--- Render failed (EXIT CODE=$err)"           # Failed? show error code
              exit 1                                              # 'exit 1' tells rush frame "Fail"
          endif
          echo --- Render OK                                      # Worked?
          exit 0                                                  # 'exit 0' tells rush frame "Done"
      endif
                                                                            
              

    ..and the same script written as a Bourne Shell:

      Bourne Simple Maya Submit/Render Script
      #!/bin/sh
      
      # SUBMIT THE JOB IF NO ARGS SPECIFIED
      if [ "$1" = "" ]; then
          if [ "$RUSH_ISDAEMON" != "" ]; then exit 1; fi              # Prevent 'network worm' style recursion
      
          scene="//server/scenes/foo.ma"                              # CHANGE THIS: scene file to render
          logdir="$scene.log"                                         # log directory based on scene pathname
      
          if [ ! -d $logdir ]; then mkdir -m 0777 $logdir; fi         # create log directory if none
      
          # SUBMIT JOB
          rush -submit << EOF
          title       SHOW/SHOT
          ram         250
          frames      1-10
          logdir      $logdir
          command     sh $0 -render $scene
          cpus        +any=5@1
      EOF
      
          if [ $? != 0 ]; then exit 1; fi                             # Submit Failed
          exit 0                                                      # Submit OK
      fi
      
      # RENDERING ON REMOTE MACHINE?
      if [ "$1" = "-render" ]; then
          echo "--- Working on frame $RUSH_FRAME"
      
          cmd="Render -s $RUSH_FRAME -e $RUSH_FRAME $2"               # command to run, $2 is scene
          echo "--- Executing: $cmd"                                  # print what we're executing
          eval $cmd                                                   # run the command..
          err=$?                                                      # ..get exit code
          if [ $err != 0 ]; then
              echo "--- Render failed (EXIT CODE=$err)"               # Failed? show error code
              exit 1                                                  # 'exit 1' tells rush frame "Fail"
          fi
          echo --- Render OK                                          # Worked?
          exit 0                                                      # 'exit 0' tells rush frame "Done"
      fi
                                                                            
              

    ..and the same script in Perl:

      Perl Simple Maya Submit/Render Script
      #!/usr/bin/perl -w
      use strict;
      $|=1;
      
      # SUBMIT JOB IF NO ARGS SPECIFIED
      if ( ! defined($ARGV[0]) ) {
          if ( defined($ENV{RUSH_ISDAEMON}) ) { exit(1); }          # Prevent 'network worm' style recursion
      
          my $scene = "//server/scenes/foo.ma";                     # CHANGE THIS: scene file to render
          my $logdir = "$scene.log";                                # log directory based on scene pathname
      
          if ( ! -d $logdir ) {                                     # create log directory if none
              unless(mkdir($logdir, 0777)) {
                  print STDERR "mkdir $logdir: $!\n"; exit(1);
              }
          }
      
          # SUBMIT JOB
          unless( open(SUBMIT, "|rush -submit") )
              { print STDERR "rush -submit: $!\n"; exit(1); }
          print SUBMIT <<"EOF";
          title       SHOW/SHOT
          ram         250
          frames      1-10
          logdir      $logdir
          command     perl $0 -render $scene
          cpus        +any=5\@1
      EOF
          close(SUBMIT);
      
          # Non-zero exit indicates submit failed
          if ( $? >> 8 ) 
              { print STDERR "--- Submit failed\n"; exit(1); }                 # Submit Failed
          exit(0);                                                             # Submit OK
      }
      
      # RENDERING ON REMOTE MACHINE?
      if ( $ARGV[0] eq "-render" ) {
          print "--- Working on frame $ENV{RUSH_FRAME}\n";
      
          my $cmd = "Render -s $ENV{RUSH_FRAME} -e $ENV{RUSH_FRAME} $ARGV[1]"; # command to run, $ARGV[1] is scene
          printf("--- Executing: %s\n", $cmd);                                 # print what we're executing
          my $err = system($cmd);                                              # run the command, get exit code
          if ( $err != 0 ) {
              printf("--- Render failed (EXIT CODE=%d)\n", $err >> 8);         # Failed? show error code
              exit(1);                                                         # exit(1) tells rush frame "Fail"
          }
          print "--- Render OK\n";                                             # Worked?
          exit(0);                                                             # exit(0) tells rush frame "Done"
      }
                                                                            
              

    ..and the same script in Python:

      Python Simple Maya Submit/Render Script
      #!/usr/bin/env python
      import os,sys
      
      # SUBMIT THE JOB IF NO ARGS SPECIFIED
      if ( len(sys.argv) <= 1 ):
          if ( os.environ.has_key("RUSH_ISDAEMON") ):                      # Prevent 'network worm' style recursion
              sys.exit(1)
      
          scene = "//server/scenes/foo.ma"                                 # CHANGE THIS: scene file to render
          logdir = scene + ".log"                                          # log directory based on scene pathname
      
          # Create log directory if none
          if ( not os.path.isdir(logdir) ):
              os.mkdir(logdir, 0777)
      
          # Submit the job
          submit = os.popen("rush -submit", 'w')
          submit.write("title    SHOW/SHOT\n" +
                       "ram      250\n" +
                       "frames   1-10\n" +
                       "logdir   %s\n" % logdir +
                       "command  python %s -render %s\n" % ( sys.argv[0] , scene ) +
                       "cpus     +any=5@1\n")
          err = submit.close()
      
          # Non-zero exit indicates submit failed
          if err:
              sys.exit(1)                                                  # Submit Failed
          sys.exit(0)                                                      # Submit OK
      
      # RENDERING ON REMOTE MACHINE?
      if ( sys.argv[1] == "-render" ):
          print "--- Working on frame %s" % os.environ["RUSH_FRAME"]
      
          # Command to execute, sys.argv[2] is scene file
          cmd = "Render -s %s -e %s %s" % \
                ( os.environ["RUSH_FRAME"], os.environ["RUSH_FRAME"], sys.argv[2] )
      
          print "--- Executing: %s" % cmd                                  # print what we're executing
          sys.stdout.flush()
          err = os.system(cmd)                                             # run command, get exit code
          if err:
              print "--- Render failed (EXIT CODE=%s)" % (err >> 8)  # Failed? show error code
              sys.exit(1)                                                  # 'sys.exit(1)' tells rush frame "Fail"
      
          print "--- Render OK"                                            # Worked?
          sys.exit(0)                                                      # 'sys.exit(0)' tells rush frame "Done"
                                                                            
              

    ..and the same script in Ruby:

      Ruby Simple Maya Submit/Render Script
      #!/usr/bin/env ruby
      
      if ARGV[0] == nil
      
          # SUBMIT THE JOB IF NO ARGS ARE SPECIFIED
      
          if ( ENV['RUSH_ISDAEMON'] )                 # Prevent 'network worm' recursion
              exit(1)
          end
      
          scene  = "//meade/net/tmp/scenes/foo.ma"    # CHANGE THIS: scene file to render
          logdir = scene + ".log"                     # log dir based on scene pathname
      
          if ( ! File.directory?(logdir) )
              Dir.mkdir(logdir, 0777)                 # create log directory if none
          end
      
          # SUBMIT JOB
          submit = IO.popen("rush -submit", "w")
          submit.puts <<-EOF
              title   SHOW/SHOT
              ram     250
              frames  1-10
              logdir  #{logdir}
              command ruby #{$0} -render #{scene}
              cpus    +any=5
          EOF
          submit.close_write()
      
          # Non-zero exit indicates submit failed
          if ($? >> 8) != 0
              print "--- submit failed\n"
              exit(1)
          end
          exit(0)
      
      elsif ARGV[0] == "-render"
      
          # RENDERING ON REMOTE MACHINE?
          scene = ARGV[1]
          print "--- Working on frame #{ENV['RUSH_FRAME']}...\n"
      
          cmd = "echo Render -r sw -s #{ENV['RUSH_FRAME']} -e #{ENV['RUSH_FRAME']} #{scene}"
          print "--- Executing: #{cmd}\n"
          system(cmd)
          if $? != 0
              printf("--- Render failed (EXIT CODE=%d)\n", ($? >> 8))
              exit(1)        # RUSH: FAIL
          else
              print "--- Render OK\n"
              exit(0)        # RUSH: OK
          end
      else
          print "#{$0}: Unknown argument '#{ARGV[0]}'\n"
          exit(1)
      end
                                                                            
              

    ..and the same script in C++:

      C Simple Maya Submit/Render Script
      
      #include <stdio.h>
      #include <stdlib.h>
      #include <errno.h>
      #include <sys/stat.h>
      #include <sys/types.h>
      #include <iostream>
      #include <string>
      
      using namespace std;
      
      // C++ EXAMPLE: Submit and Render
      //
      //        UNIX COMPILE: g++ filename.cpp -o filename
      //     WINDOWS COMPILE: cl /TP filename.cpp
      //
      
      #ifdef _WIN32
      #include <direct.h>
      #define popen           _popen 
      #define pclose          _pclose 
      #define mkdir(a,b)      _mkdir(a)
      #endif
      
      int main(int argc, char **argv) {
          // SUBMIT THE JOB IF NO ARGS SPECIFIED
          if ( argc < 2 ) {
              if ( getenv("RUSH_ISDAEMON") ) exit(1);                            // Prevent 'network worm' style recursion
      
              string scene = "/meade/net/tmp/scenes/foo.ma";                     // CHANGE THIS: scene file to render
              string logdir = scene; logdir += ".log";                           // log directory based on scene pathname
      
              // MAKE LOGDIR IF NONE
              struct stat buf;
              if ( stat(logdir.c_str(), &buf) < 0 && errno == ENOENT ) {
                  if ( mkdir(logdir.c_str(), 0777) < 0 ) {                       // create log directory if none
                      perror(logdir.c_str()); exit(1);
                  }
              }
      
              // Submit the job
              FILE *fp;
              if ( ( fp = popen("rush -submit", "w") ) == NULL )
                  { perror("couldn't popen(rush -submit)"); exit(1); }
              fprintf(fp, "title     SHOW/SHOT\n");
              fprintf(fp, "ram       250\n");
              fprintf(fp, "frames    1-10\n");
              fprintf(fp, "logdir    %s\n", logdir.c_str());
              fprintf(fp, "command   %s -render %s\n", argv[0], scene.c_str());
              fprintf(fp, "cpus      +any=5@1\n");
              if ( pclose(fp) < 0 )                                                      // Submit Failed
                  { cerr << "--- Submit failed" << endl; exit(1); }                      // Submit OK
              exit(0);
          }
      
          // RENDERING ON REMOTE MACHINE?
          if ( argc >= 2 && strcmp(argv[1], "-render") == 0 ) {
              cout << "--- Working on frame " << getenv("RUSH_FRAME") << endl;
      
              string cmd = "Render";                                                     // build command to run..
                     cmd += " -s "; cmd += getenv("RUSH_FRAME");
                     cmd += " -e "; cmd += getenv("RUSH_FRAME");
                     cmd += " ";    cmd += argv[2];                                      // ..argv[2] will be scene filename
      
              cerr << "--- Executing: " << cmd << endl;                                  // print command being executed
              int err = system(cmd.c_str());                                             // run command, get exit code
              if ( err != 0 ) {
                  cerr << "--- Render failed (EXIT CODE=" << (err>>8) << ")" << endl;    // Failed? show error code
                  exit(1);                                                               // exit(1) tells rush frame "Fail"
              }
              cerr << "--- Render OK" << endl;                                           // Worked?
              exit(0);                                                                   // exit(0) tells rush frame "Done"
          }
          return(0);
      }
                                                                            
              








  Submit/Render Scripts That Auto-Start Irush
    Here are fleshed out versions of the above simple submit scripts that auto-launch irush, and adds batching.

    Here's the modified Csh script:

      Csh 'Autostart Irush' Maya Submit/Render Script
      #!/bin/csh -f
      
      # SUBMIT THE JOB IF NO ARGS SPECIFIED
      if ( "$1" == "" ) then
          if ( "$RUSH_ISDAEMON" != "" ) exit 1        # Prevent 'network worm' style recursion
      
          # User should change these as needed
          set sfrm   = 1                              # Start frame
          set efrm   = 53                             # End frame
          set batch  = 5                              # Batch frames (1 disables)
          set scene  = "//server/scenes/foo.ma"       # Scene file to render
          set logdir = "$scene.log"                   # Log directory based on scene pathname
             
          if ( ! -d $logdir ) mkdir -m 0777 $logdir   # create log directory if none
      
          # SUBMIT THE JOB
          #    'eval' parses the 'setenv RUSH_JOBID' environment setting
          #
          eval `rush -submit` << EOF
          title       SHOW/SHOT
          ram         250
          frames      $sfrm-$efrm,$batch
          logdir      $logdir
          command     csh $0 -render $scene $batch $efrm
          cpus        +any=5@1
      EOF
          if ( $status != 0 ) exit 1                  # Submit Failed
      
          # Submit OK
          #    Print jobid, start irush monitoring job
          #
          echo "--- RUSH_JOBID is $RUSH_JOBID"
          irush -button Frames
          exit 0
      endif
      
      # RENDERING ON REMOTE MACHINE?
      if ( "$1" == "-render" ) then
          set scene = "$2"
      
          # HANDLE BATCHING
          @ batch   = $3
          @ lastfrm = $4
          @ sfrm    = $RUSH_FRAME
          @ efrm    = $RUSH_FRAME + $batch - 1
          if ( $efrm > $lastfrm ) @ efrm = $lastfrm
      
          # PRINT FRAMES BEING RENDERED
          if ( $sfrm == $efrm ) echo "--- Working on frame $sfrm"
          if ( $sfrm != $efrm ) echo "--- Working on frames $sfrm - $efrm"
      
          # START RENDER, CHECK FOR ERRORS
          set cmd = "Render -s $sfrm -e $efrm $scene"    # command to run
          echo "--- Executing: $cmd"                     # print what we're executing
          $cmd                                           # run the command
          set err = $status                              # check for non-zero exit code from Render
          if ( $err != 0 ) then
              echo "--- Render failed (EXIT CODE=$err)"  # Failed? show error code
              exit 1                                     # 'exit 1' tells rush frame "Fail"
          endif
          echo "--- Render OK"                           # Worked?
          exit 0                                         # 'exit 0' tells rush frame "Done"
      endif
      
      # BAD ARGUMENT
      echo "${0}: unknown argument $1"
      exit 1
                                                                            
              

    ..and the same script written as a Bourne Shell:

      Bourne 'Autostart Irush' Maya Submit/Render Script
      #!/bin/sh
      
      # SUBMIT THE JOB IF NO ARGS SPECIFIED
      if [ "$1" = "" ]; then
          if [ "$RUSH_ISDAEMON" != "" ]; then exit 1; fi  # Prevent 'network worm' style recursion
      
          # User should change these as needed
          sfrm=1                                          # Start frame
          efrm=53                                         # End frame
          batch=5                                         # Batch frames (1 disables)
          scene="//server/scenes/foo.ma"                  # Scene file to render
          logdir="$scene.log"                             # Log directory based on scene pathname
      
          if [ ! -d $logdir ]; then                       # create log directory if none
              mkdir -m 0777 $logdir
          fi
      
          # SUBMIT JOB, GRAB OUTPUT
          RUSHOUT=$(rush -submit << EOF
          title       SHOW/SHOT
          ram         250
          frames      $sfrm-$efrm,$batch
          logdir      $logdir
          command     sh $0 -render $scene $batch $efrm
          cpus        +any=5@1
      EOF
      )
          echo "$RUSHOUT"
          if [ $? != 0 ]; then exit 1; fi          # Submit Failed
      
          # Submit OK
          #    Parse jobid, print, start irush
          #
          export RUSH_JOBID=${RUSHOUT##setenv RUSH_JOBID }
          echo "--- RUSH_JOBID is $RUSH_JOBID"
          irush -button Frames
          exit 0
      fi
      
      # RENDERING ON REMOTE MACHINE?
      if [ "$1" = "-render" ]; then
          scene="$2"
          batch="$3"
          lastfrm="$4"
          sfrm=$RUSH_FRAME
          efrm=$(( $RUSH_FRAME + $batch - 1 ))
          if [ $efrm -gt $lastfrm ]; then efrm=$lastfrm; fi
      
          # PRINT FRAMES BEING RENDERED
          if [ $efrm -gt $lastfrm ]; then
              echo "--- Working on frame $sfrm"
          else
              echo "--- Working on frames $sfrm - $efrm"
          fi
      
          # START RENDER, CHECK FOR ERRORS
          cmd="Render -s $sfrm -e $efrm $scene"            # command to run
          echo "--- Executing: $cmd"                       # print what we're executing
          eval $cmd                                        # run the command
          err=$?                                           # check for non-zero exit code from Render
          if [ $err != 0 ]; then
              echo "--- Render failed (EXIT CODE=$err)"    # Failed? show error code
              exit 1                                       # 'exit 1' tells rush frame "Fail"
          fi
          echo --- Render OK                               # Worked?
          exit 0                                           # 'exit 0' tells rush frame "Done"
      fi
      
      # BAD ARGUMENT
      echo "${0}: unknown argument $1"
      exit 1
                                                                            
              

    ..and the same script in Perl:

      Perl 'Autostart Irush' Maya Submit/Render Script
      
      #!/usr/bin/perl -w
      use strict;
      $|=1;
      
      # SUBMIT JOB IF NO ARGS SPECIFIED
      if ( ! defined($ARGV[0]) ) {
          if ( defined($ENV{RUSH_ISDAEMON}) ) { exit(1); }  # Prevent 'network worm' style recursion
      
          # User should change these as needed
          my $sfrm   = 1;                                   # Start frame
          my $efrm   = 53;                                  # End frame
          my $batch  = 5;                                   # Batch frames (1 disables)
          my $scene  = "//server/scenes/foo.ma";            # Scene file to render
          my $logdir = "$scene.log";                        # Log directory based on scene pathname
      
          if ( ! -d $logdir )                               # create log directory if none
              { mkdir($logdir, 0777); }
      
          # SUBMIT THE JOB
          #    Save output to a temp file so we can parse back jobid..
          #
          my $tmpfile = ( ( -d "/var/tmp" ) ? "/var/tmp" : "c:/temp" ) . "/submit-out.$$";
          unless( open(SUBMIT, "|rush -submit > $tmpfile") )
              { print STDERR "rush -submit: $!\n"; exit(1); }
          print SUBMIT <<"EOF";
          title       SHOW/SHOT
          ram         250
          frames      $sfrm-$efrm,$batch
          logdir      $logdir
          command     perl $0 -render $scene $batch $efrm
          cpus        +any=5\@1
      EOF
          close(SUBMIT);
          my $err = $?;        # Save exit code for submit
      
          # Parse jobid from submit output, remove tmpfile
          my $jobid;
          open(RUSHOUT, "<$tmpfile");
          while ( <RUSHOUT> ) {
              print $_;
              if ( /RUSH_JOBID.(\S+)/ ) { $jobid = $1; }
          }
          close(RUSHOUT);
          unlink($tmpfile);
      
          # Submit failed?
          if ( $? >> 8 || ! defined($jobid) )
              { print STDERR "--- Submit failed\n"; exit(1); }
          
          # Submit OK?
          #    Set RUSH_JOBID, start irush monitoring job
          #
          $ENV{RUSH_JOBID} = $jobid;
          system("irush -button Frames");
          exit(0);
      }
      
      # RENDERING ON REMOTE MACHINE?
      if ( $ARGV[0] eq "-render" ) {
          my $scene   = $ARGV[1];
          my $batch   = $ARGV[2];
          my $lastfrm = $ARGV[3];
          my $sfrm    = $ENV{RUSH_FRAME};
          my $efrm    = $ENV{RUSH_FRAME} + $batch - 1;
          if ( $efrm > $lastfrm )
              { $efrm = $lastfrm; }
      
          # PRINT FRAMES BEING RENDERED
          if ( $sfrm == $efrm )
              { print "--- Working on frame $sfrm\n"; }
          else
              { print "--- Working on frames $sfrm - $efrm\n"; }
      
          # START RENDER, CHECK FOR ERRORS
          my $cmd = "Render -s $sfrm -e $efrm $scene";                  # command to run, $ARGV[1] is scene
          printf("--- Executing: %s\n", $cmd);
          my $err = system($cmd);
          if ( $err != 0 ) {
              printf("--- Render failed (EXIT CODE=%d)\n", $err >> 8);  # Failed? show error code
              exit(1);                                                  # exit(1) tells rush frame "Fail"
          }
          print "--- Render OK\n";                                      # Worked?
          exit(0);                                                      # exit(0) tells rush frame "Done"
      }
      
      # BAD ARGUMENT
      print STDERR "$0: unknown argument $ARGV[0]\n";
      exit(1);
                                                                            
              

    ..and the same script in Python:

      Python 'Autostart Irush' Maya Submit/Render Script
      #!/usr/bin/env python
      import os,sys,re
      
      # Parse jobid from rush submit
      def ParseJobid(rushoutfile):
          rushout = open(rushoutfile, 'r')
          rushout_lines = ""
          while 1:
              line = rushout.readline()
              if ( line == "" ):
                  break
              rushout_lines += line
          print rushout_lines
          rushout.close()
          return(re.search("RUSH_JOBID.(\S+)", rushout_lines).groups()[0])
      
      # SUBMIT THE JOB IF NO ARGS SPECIFIED
      if len(sys.argv) <= 1:
          if ( os.environ.has_key("RUSH_ISDAEMON") ):  # Prevent 'network worm' style recursion
              sys.exit(1)
      
          # User should change these as needed
          sfrm   = 1                                   # Start frame
          efrm   = 53                                  # End frame
          batch  = 5                                   # Batch frames (1 disables)
          scene  = "//server/scenes/foo.ma"            # Scene file to render
          logdir = scene + ".log"                      # Log directory based on scene pathname
      
          # Create log directory if none
          if ( not os.path.isdir(logdir) ):
              os.mkdir(logdir, 0777)
      
          # SUBMIT THE JOB
          #    Save output to a temp file so we can parse back jobid..
          #
          tmpfile = "/var/tmp"
          if ( os.path.isdir("c:/temp") ):
              tmpfile = "c:/temp"
          tmpfile = "%s/submit-out.%d" % ( tmpfile, os.getpid() )
      
          # Submit the job
          submit = os.popen("rush -submit > " + tmpfile, 'w')
          submit.write("title    SHOW/SHOT\n" +
                       "ram      250\n" +
                       "frames   %d-%d,%d\n" % ( sfrm, efrm, batch) +
                       "logdir   %s\n" % logdir +
                       "command  python %s -render %s %s %s\n" % ( sys.argv[0], scene, batch, efrm ) +
                       "cpus     +any=5@1\n")
          err = submit.close()
      
          # Read submit output, parse jobid, remove tmp file
          os.environ["RUSH_JOBID"] = ParseJobid(tmpfile);
          os.remove(tmpfile)
      
          # Submit Failed
          if ( err or os.environ["RUSH_JOBID"] == "" ):
              sys.exit(1)
      
          # Submit OK
          print "--- Starting irush.."
          os.system("irush -button Frames")
          sys.exit(0)
      
      # RENDERING ON REMOTE MACHINE?
      if ( sys.argv[1] == "-render" ):
          scene   = sys.argv[2]
          batch   = int(sys.argv[3])
          lastfrm = int(sys.argv[4])
          sfrm    = int(os.environ["RUSH_FRAME"])
          efrm    = int(os.environ["RUSH_FRAME"]) + batch - 1
          if ( efrm > lastfrm ):
              efrm = lastfrm
      
          # PRINT FRAMES BEING RENDERED
          if ( sfrm == efrm ):
              print "--- Working on frame %d" % sfrm
          else:
              print "--- Working on frames %d - %d" % ( sfrm, efrm )
      
          # START RENDER, CHECK FOR ERRORS
          cmd = "Render -s %d -e %d %s" % ( sfrm, efrm, sys.argv[2] )
          print "--- Executing: %s" % cmd
          sys.stdout.flush()
          err = os.system(cmd)
          if err:
              print "--- Render failed (EXIT CODE=%s)" % (err >> 8)  # Failed? show error code
              sys.exit(1)                                            # 'sys.exit(1)' tells rush frame "Fail"
      
          print "--- Render OK"                                      # Worked?
          sys.exit(0)                                                # 'sys.exit(0)' tells rush frame "Done"
      
      # BAD ARGUMENT
      stderr.write("%s: unknown argument %s\n" % ( sys.argv[0], sys.argv[1] ) )
      sys.exit(1)
                                                                            
              

    ..and the same script in C++:

      C 'Autostart Irush' Maya Submit/Render Script
      
      #include <stdio.h>
      #include <stdlib.h>
      #include <errno.h>
      #include <sys/stat.h>
      #include <sys/types.h>
      #include <iostream>
      #include <string>
      
      using namespace std;
      
      // C++ EXAMPLE: Submit and Render
      //
      //        UNIX COMPILE: g++ filename.cpp -o filename
      //     WINDOWS COMPILE: cl /TP filename.cpp
      //
      
      #ifdef _WIN32
      #include <direct.h>
      #define popen           _popen 
      #define pclose          _pclose 
      #define mkdir(a,b)      _mkdir(a)
      #endif
      
      // Parse jobid from rush submit
      string ParseJobid(const char *tmpfile) {
          string jobid;
          FILE *fp;
          if ( ( fp = fopen(tmpfile, "r") ) != 0 ) {
              char s[1024];
              while ( fgets(s, 1023, fp) ) {
                  const char *ss;
                  if ( ( ss = strstr(s, "RUSH_JOBID") ) != NULL ) {
                      char c;
                      char tmp[80];
                      if ( sscanf(ss, "RUSH_JOBID%c%79s", &c, tmp) == 2 ) {
                          jobid = tmp;
                      }
                  }
              }
              fclose(fp);
          } else {
              perror(tmpfile);
          }
          return(jobid);
      }
      
      // See if pathname is an existing directory
      int IsDirectory(const char *pathname) {
          struct stat buf;
          return ( stat(pathname, &buf) == 0 && S_ISDIR(buf.st_mode) ? 1 : 0 );
      }
      
      int main(int argc, char **argv) {
          // SUBMIT THE JOB IF NO ARGS SPECIFIED
          if ( argc < 2 ) {
              if ( getenv("RUSH_ISDAEMON") ) exit(1);                  // Prevent 'network worm' style recursion
      
              string scene = "/meade/net/tmp/scenes/foo.ma";           // CHANGE THIS: scene file to render
              string logdir = scene; logdir += ".log";                 // log directory based on scene pathname
      
              // MAKE LOGDIR IF NONE
              if ( ! IsDirectory(logdir.c_str()) ) {
                  if ( mkdir(logdir.c_str(), 0777) < 0 ) {             // create log directory if none
                      perror(logdir.c_str()); exit(1);
                  }
              }
      
              // Submit the job
              char tmpfile[80];
              if ( IsDirectory("c:/temp") )
                  { sprintf(tmpfile, "c:/temp/submit-out.%ld", (unsigned long)getpid()); }
              else
                  { sprintf(tmpfile, "/var/tmp/submit-out.%ld", (unsigned long)getpid()); }
      
              string cmd = "rush -submit > "; cmd += tmpfile;
              FILE *fp;
              if ( ( fp = popen(cmd.c_str(), "w") ) == NULL )
                  { perror(cmd.c_str()); exit(1); }
              fprintf(fp, "title     SHOW/SHOT\n");
              fprintf(fp, "ram       250\n");
              fprintf(fp, "frames    1-10\n");
              fprintf(fp, "logdir    %s\n", logdir.c_str());
              fprintf(fp, "command   %s -render %s\n", argv[0], scene.c_str());
              fprintf(fp, "cpus      +any=5@1\n");
              int err = pclose(fp);
      
              // Open the tmpfile, parse the jobid (if any)
              string jobid = ParseJobid(tmpfile);             // get jobid from submit
              setenv("RUSH_JOBID", jobid.c_str(), 1);         // set RUSH_JOBID environment variable
              remove(tmpfile);                                // remove tmpfile
      
              // Submit Failed?
              if ( err < 0 || jobid == "" )
                  { cerr << "--- Submit failed" << endl; exit(1); }
      
              // Submit OK
              cerr << "--- Starting irush.." << endl;
              system("irush -button Frames");
              exit(0);
          }
      
          // RENDERING ON REMOTE MACHINE?
          if ( argc >= 2 && strcmp(argv[1], "-render") == 0 ) {
              cout << "--- Working on frame " << getenv("RUSH_FRAME") << endl;
      
              string cmd = "Render";
              cmd += " -s "; cmd += getenv("RUSH_FRAME");
              cmd += " -e "; cmd += getenv("RUSH_FRAME");
              cmd += " ";    cmd += argv[2];                                             // argv[2] will be scene filename
      
              int err;
              cerr << "--- Executing: " << cmd << endl;
              if ( ( err = system(cmd.c_str()) ) != 0 ) {
                  cerr << "--- Render failed (EXIT CODE=" << (err>>8) << ")" << endl;    // Failed? show error code
                  exit(1);                                                               // exit(1) tells rush frame "Fail"
              }
              cerr << "--- Render OK" << endl;                                           // Worked?
              exit(0);                                                                   // exit(0) tells rush frame "Done"
          }
          return(0);
      }