I have the below code where I want to send qsub command using system("qsub"). The problem is I can't send this command to the dynamically created directories. However, I can send it to the manually created directory.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <zlib.h>
main(){
const char *a[5];
int i, j ,k, ii, jj, kk;
char str[256];
FILE *fp, *source, *target, *fp1;
char ch[300];
char str1[256];
char sbuff[300];
printf("Start Here ...\n");
a[0] = "submit.sh";
a[1] = "run.prm";
a[2] = "name.txt";
a[3] = "prot.pdb";
a[4] = "step2_out.pdb";
for (i=1;i<6;i++){
sprintf(str,"_%d", i);
mkdir(str, 0755); // Create temporary directories
for (j=0;j<5;j++){
sprintf(str,"%s", a[j]);
source = fopen(str, "r");
if( source == NULL )
{
printf("Error in doStepOneAndTwo, can't open file source \n");
return -1;
}
sprintf(str,"_%d/%s", i, a[j]);
target = fopen(str, "w+");
if( target == NULL )
{
fclose(source);
printf("Error in doStepOneAndTwo, can't open file target %s \n",str);
return -1;
}
while( (fgets(ch, sizeof(ch), source))) {
if (j == 1){
if (strstr(ch, "(DO_PREMCCE)")){
ch[0] = 'f';
}
else if (strstr(ch, "(DO_ROTAMERS)")){
ch[0] = 'f';
}
else if (strstr(ch, "(DO_MONTE)")){
ch[0] = 'f';
}
else if (strstr(ch, "(DELPHI_STEP)")){
ch[0] = 'f';
}
fputs(ch, target);
}else {
fputs(ch, target);
}
}
}
sprintf(str1,"chmod +x _%d/submit.sh", i);
system(str1);
// Submiting the jobs
if (getcwd(sbuff, sizeof(sbuff)) != NULL)
printf("Current working dir 1: %s\n", sbuff);
else
printf("getcwd() error");
sprintf(str,"_%d/", i);
chdir(str);
system("qsub submit.sh"); // This line doesn't works, the above directories are dynamically created (str)
chdir(sbuff);
}
// Submit the job
chdir("1l2y");
system("qsub submit.sh"); // This line works, the above directory is manually created (1l2y)
chdir(sbuff);
return 0;
}
The error I get "Unable to run job: job rejected: no script in your request." However, if I change my command from system("qsub submit.sh") to system("rm *") everything works just fine. I don't know why I can't send this command to the dynamically created directories.
Aucun commentaire:
Enregistrer un commentaire