Hi, I'm writing a piece of software that lets me distribute executions of the type same program-multiple data in a computing server through PVM. This software has a module for Maple executions, one for C, one for Python and one for Pari. Now I'm trying to write the code for a Sage module.
The idea is that i have a master who sends tasks to several slaves, each task consists on executing the same Sage script but using different values for the variables taskId
and taskArgs
. The slave forks a process and executes a chunk such as this one:
// NULL-terminated array of strings
char **args;
int nargs=2;
args = (char**)malloc((nargs+1)*sizeof(char*));
// Do not malloc for NULL
for (i=0;i<nargs;i++)
args[i] = malloc(BUFFER_SIZE);
// Fill up the array with strings
sprintf(args[0],"sage");
sprintf(args[1],"-c \"taskId=%d;taskArgs=[%s];load('%s');\"",taskNumber,arguments,inp_programFile);
args[2] = NULL;
// Call the execution and check for errors
err = execvp(args[0],args);
perror("ERROR:: child Sage process");
exit(err);
For example, an instance of this code would be executing
sage -c "taskId=71;taskArgs=[0,73,74,0];load('test.sage')"
,
where test.sage prints the arguments or whatever.
Now comes the question. If i execute the previous command from the command line i get the expected result (the two prints). However, if i execute my C program (which works corectly for Maple, C, Python and Pari using a very similar approach) i get this error:
sage-run received unknown option: -c "taskId=71;taskArgs:=[0,73,74,0];load('test.sage')"
I have already tried changing the double quotes "
to single quotes '
, using only a single, very simple argument from C (e.g. sage -c "print(1);"
), all to no avail.
Am I missing something? How can the same command work from the command line but not when i use execvp
from within C?
Thanks in advanced for any help!
(I know I could adapt my Python module to read Sage scripts, but i want a standalone module for Sage because the Python one uses sys.args
and I'd like to keep the Sage scripts as simple as possible for the users of the software)