objective c - How can I prepare arguments for NSTask from UI items -


i have cocoa app user allowed execute shell commands (just using terminal) entering commands in ui items nstextbox. app allows has few predetermined parameters converted characters inside app.

the app allows multithreads in few commands can run @ same time.

the challenge facing let user enter commands in terminal spaces , etc. have difficulty breaking down user enters nsarray element arguments fed nstask. example, there paths or parameters has spaces in between, e.g. /users/application support/testfolder/ or 'test - b'

what doing have fixed number of nstextboxes , each nstextbox allows 1 parameter. 1 other issue if command has number of arguments less total nstextboxes, have give "" argument(s) , hence, command may not executed correctly. want make more flexible user enter is. then, app able handle characters , run user-entered command using nstask.

.... paramarray = [cmdparam componentsseparatedbystring:@","];  nsstring *launchpath = [paramarray objectatindex:0];  if ([launchpath rangeofstring:@"\""].location == nsnotfound) {     int nlineno = [launchpath integervalue];     launchpath = [self cmdreading:nlineno uutindex:nuut]; } else {     launchpath = [launchpath stringbyreplacingoccurrencesofstring:@"\"" withstring:@""]; }  nsstring *param1 = [paramarray objectatindex:1];  if ([param1 rangeofstring:@"\""].location == nsnotfound) {     if ([param1 caseinsensitivecompare:@"uut_number"] == nsorderedsame) {         param1 = [nsstring stringwithformat:@"uut%d", nuut+1];     }     else if ([param1 caseinsensitivecompare:@"get_uut_number"] == nsorderedsame) {         param1 = [nsstring stringwithformat:@"%d", nuut+1];     }     else if ([param1 length] == 0) {         param1 = @"";     }     else {         int nlineno = [param1 integervalue];         param1 = [self cmdreading:nlineno uutindex:nuut];     } } else {     param1 = [param1 stringbyreplacingoccurrencesofstring:@"\"" withstring:@""]; }  nsstring *param2 = [paramarray objectatindex:2];  if ([param2 rangeofstring:@"\""].location == nsnotfound) {     if ([param2 caseinsensitivecompare:@"uut_number"] == nsorderedsame) {         param2 = [nsstring stringwithformat:@"uut%d", nuut+1];     }     else if ([param2 caseinsensitivecompare:@"get_uut_number"] == nsorderedsame) {         param2 = [nsstring stringwithformat:@"%d", nuut+1];     }     else if ([param2 length] == 0) {         param2 = @"";     }     else {         int nlineno = [param2 integervalue];         param2 = [self cmdreading:nlineno uutindex:nuut];  }     }     else {         param2 = [param2 stringbyreplacingoccurrencesofstring:@"\"" withstring:@""];     }      nsstring *param3 = [paramarray objectatindex:3];      if ([param3 rangeofstring:@"\""].location == nsnotfound) {         if ([param3 caseinsensitivecompare:@"uut_number"] == nsorderedsame) {        param3 = [nsstring stringwithformat:@"uut%d", nuut+1];      }     else if ([param3 caseinsensitivecompare:@"get_uut_number"] == nsorderedsame) {         param3 = [nsstring stringwithformat:@"%d", nuut+1];     }     else if ([param3 length] == 0) {         param3 = @"";     }     else {         int nlineno = [param3 integervalue];         param3 = [self cmdreading:nlineno uutindex:nuut];     } } else {     param3 = [param3 stringbyreplacingoccurrencesofstring:@"\"" withstring:@""]; }  nsstring *param4 = [paramarray objectatindex:4];  if ([param4 rangeofstring:@"\""].location == nsnotfound) {     if ([param4 caseinsensitivecompare:@"uut_number"] == nsorderedsame) {         param4 = [nsstring stringwithformat:@"uut%d", nuut+1];     }     else if ([param4 caseinsensitivecompare:@"get_uut_number"] == nsorderedsame) {         param4 = [nsstring stringwithformat:@"%d", nuut+1];     }     else if ([param4 length] == 0) {         param4 = @"";     }     else {         int nlineno = [param4 integervalue];         param4 = [self cmdreading:nlineno uutindex:nuut];     } } else {     param4 = [param4 stringbyreplacingoccurrencesofstring:@"\"" withstring:@""]; }  nsstring *param5 = [paramarray objectatindex:5];  if ([param5 rangeofstring:@"\""].location == nsnotfound) {     if ([param5 caseinsensitivecompare:@"uut_number"] == nsorderedsame) {         param5 = [nsstring stringwithformat:@"uut%d", nuut+1];     }     else if ([param5 caseinsensitivecompare:@"get_uut_number"] == nsorderedsame) {         param5 = [nsstring stringwithformat:@"%d", nuut+1];     }     else if ([param5 length] == 0) {         param5 = @"";     }     else {         int nlineno = [param5 integervalue];         param5 = [self cmdreading:nlineno uutindex:nuut];     } } else {     param5 = [param5 stringbyreplacingoccurrencesofstring:@"\"" withstring:@""]; }  nsstring *param6 = [paramarray objectatindex:6];  if ([param6 rangeofstring:@"\""].location == nsnotfound) {     if ([param6 caseinsensitivecompare:@"uut_number"] == nsorderedsame) {         param6 = [nsstring stringwithformat:@"uut%d", nuut+1];     }     else if ([param6 caseinsensitivecompare:@"get_uut_number"] == nsorderedsame) {         param6 = [nsstring stringwithformat:@"%d", nuut+1];     }     else if ([param6 length] == 0) {         param6 = @"";     }     else {         int nlineno = [param6 integervalue];         param6 = [self cmdreading:nlineno uutindex:nuut];      } } else {     param6 = [param6 stringbyreplacingoccurrencesofstring:@"\"" withstring:@""]; }  nsstring *param7 = [paramarray objectatindex:7];  if ([param7 rangeofstring:@"\""].location == nsnotfound) {     if ([param7 caseinsensitivecompare:@"uut_number"] == nsorderedsame) {         param7 = [nsstring stringwithformat:@"uut%d", nuut+1];     }     else if ([param7 caseinsensitivecompare:@"get_uut_number"] == nsorderedsame) {         param7 = [nsstring stringwithformat:@"%d", nuut+1];     }     else if ([param7 length] == 0) {         param7 = @"";     }     else {         int nlineno = [param7 integervalue];         param7 = [self cmdreading:nlineno uutindex:nuut];     } } else {     param7 = [param7 stringbyreplacingoccurrencesofstring:@"\"" withstring:@""]; }       nslog(@"_terminal_command uut:%d, launchpath=%@", nuut+1, launchpath);     nslog(@"_terminal_command uut:%d, param1=%@", nuut+1, param1);     nslog(@"_terminal_command uut:%d, param2=%@", nuut+1, param2);     nslog(@"_terminal_command uut:%d, param3=%@", nuut+1, param3);     nslog(@"_terminal_command uut:%d, param4=%@", nuut+1, param4);     nslog(@"_terminal_command uut:%d, param5=%@", nuut+1, param5);     nslog(@"_terminal_command uut:%d, param6=%@", nuut+1, param6);     nslog(@"_terminal_command uut:%d, param7=%@", nuut+1, param7);      nstask* task = [nstask new];      [task setlaunchpath:launchpath];     [task setarguments:[nsarray arraywithobjects:param1,                                 param2, param3,                                 param4, param5,                                 param6, param7, nil]];  ... 


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -