Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. NSLog(@"myString is :%@", myString);
  2. int processID = [myString intValue];
  3.  
  4. NSTask *task;
  5. task = [[NSTask alloc] init];
  6. [task setLaunchPath: @"/bin/ps"];
  7.  
  8. arguments = [NSArray arrayWithObjects: @"aux", [NSString stringWithFormat:@"%i", processID],nil];
  9.  
  10. [task setArguments: arguments];
  11.  
  12. NSPipe *pipe;
  13. pipe = [NSPipe pipe];
  14. //[task setStandardOutput: pipe];
  15. [task setStandardOutput:pipe];
  16.  
  17. NSFileHandle *file;
  18. file = [pipe fileHandleForReading];
  19.  
  20. [task launch];
  21.  
  22. NSData *data;
  23. data = [file readDataToEndOfFile];
  24.  
  25. NSString *string;
  26. string = [[NSString alloc] initWithData: data
  27. encoding: NSUTF8StringEncoding];
  28.  
  29. // NSLog(@"%@",string);
  30.  
  31.  
  32. NSArray *lines= [string componentsSeparatedByString:@"n"];
  33.  
  34. NSString *lastline = [lines objectAtIndex:[lines count]-2];
  35. // NSLog(@"%@",lastline);
  36.  
  37.  
  38.  
  39. lines2= [lastline componentsSeparatedByString:@" "];
  40. NSLog(@"%@",lines2);
  41. for (int i=0; i<[lines2 count]; i++) {
  42.  
  43. if([[lines2 objectAtIndex:i] isEqualToString:@""]){
  44. [lines2 removeObjectAtIndex:i];
  45. }
  46.  
  47. }
  48. for (int i=0; i<[lines2 count]; i++) {
  49.  
  50. if([[lines2 objectAtIndex:i] isEqualToString:@""]){
  51. [lines2 removeObjectAtIndex:i];
  52. }
  53.  
  54. }
  55. for (int i=0; i<[lines2 count]; i++) {
  56.  
  57. if([[lines2 objectAtIndex:7] isEqualToString:@"Ss"]){
  58. [[lines2 objectAtIndex:0] replaceObjectAtIndex:7 withObject:@"SS (Running)"];
  59.  
  60. }
  61. }
  62.  
  63. - (NSArray *)componentsSeparatedByString:(NSString *)separator
  64.  
  65. [[lines2 objectAtIndex:0] replaceObjectAtIndex:7 withObject:@"SS (Running)"];
  66. ^^^^^^^^^^^^^^^^^^^^^^^^ This is wrong
  67.  
  68. NSMutableArray * myMutableArray = [NSMutableArray arrayWithArray:lines2];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement