#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
/* C EXAMPLE: Submit and Render
*
* This program acts as both a submit and render script.
* It is important to invoke this program initially with an absolute path,
* so the program can call itself correctly from other machines.
*
* UNIX COMPILE:
* cc filename.c -o filename
*
* WINDOWS COMPILE:
* vcvars32
* cl filename.c
*/
#ifdef _WIN32
#include <direct.h>
#define popen _popen
#define pclose _pclose
#define mkdir(a,b) _mkdir(a)
#endif
int main(int argc, char **argv)
{
if ( argc >= 2 && strcmp(argv[1], "-render") == 0 )
{
/* CALLED AS A RENDER SCRIPT?
* Invoke maya, return exit code.
*/
int t;
char cmd[4096];
sprintf(cmd, "mayabatch -render -s %s -e %s",
getenv("RUSH_FRAME"),
getenv("RUSH_FRAME"));
for ( t=2; t<argc; t++ )
{ strcat(cmd, " "); strcat(cmd, argv[t]); }
fprintf(stderr, "Executing: %s\n", cmd);
t = system(cmd) >> 8;
if ( t != 0 )
{ fprintf(stderr, "MAYA FAILED: EXIT CODE=%d\n", t); exit(1); }
fprintf(stderr, "MAYA SUCCESS\n");
exit(0);
}
else
{
/* CALLED AS A SUBMIT SCRIPT?
* Then prompt for info, and submit the job
*/
FILE *fp;
char title[40];
char frames[40];
char scene[1024];
char cpus[1024];
char cmd[1024];
char logdir[1024];
fprintf(stderr, " Enter title for job: ");
fgets(title, sizeof(title)-1, stdin);
title[strlen(title)-1] = '\0';
fprintf(stderr, " Enter the scene file: ");
fgets(scene, sizeof(scene)-1, stdin);
scene[strlen(scene)-1] = '\0';
fprintf(stderr, "Enter the frame range: ");
fgets(frames, sizeof(frames)-1, stdin);
frames[strlen(frames)-1] = '\0';
fprintf(stderr, " Enter the cpus: ");
fgets(cpus, sizeof(cpus)-1, stdin);
cpus[strlen(cpus)-1] = '\0';
/* MAKE LOGDIR BASED ON TITLE OF JOB
* There are cleaner ways to do this.
*/
{
int oldmask = umask(0);
sprintf(logdir, "//tahoe/net/tmp/%s", title);
if ( mkdir(logdir, 0777) < 0 && errno != EEXIST )
{ perror(logdir); exit(1); }
umask(oldmask);
}
/* SUBMIT THE JOB
* Feed the submit commands down a pipe.
*/
if ( ( fp = popen("rush -submit", "w") ) == NULL )
{ perror("couldn't popen(rush -submit)"); exit(1); }
fprintf(fp, "title %s\n", title);
fprintf(fp, "ram 1\n");
fprintf(fp, "frames %s\n", frames);
fprintf(fp, "logdir %s\n", logdir);
fprintf(fp, "command %s -render %s\n", argv[0], scene);
fprintf(fp, "cpus %s\n", cpus);
pclose(fp);
exit(0);
}
/*NOTREACHED*/
}
|