Domanda

In Cacao, sto cercando di implementare un pulsante, che quando l'utente fa clic sul catturerà il rapporto System Profiler e incollarlo sul desktop.

Codice

 NSTask *taskDebug;
NSPipe *pipeDebug;
 taskDebug = [[NSTask alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(taskFinished:)       name:NSTaskDidTerminateNotification object:taskDebug];
 [profilerButton setTitle:@"Please Wait"];
 [profilerButton setEnabled:NO];

  [taskDebug setLaunchPath: @"/usr/sbin/system_profiler"];

  NSArray *args = [NSArray arrayWithObjects:@"-xml",@"-detailLevel",@"full",@">", @" 
    ~/Desktop/Profiler.spx",nil];
  [taskDebug setArguments:args];


  [taskDebug launch];

Ma questo non salva il file sul desktop. avere NSArray * args = [arrayWithObjects NSArray: @ "- XML", @ "- detailLevel", @ "pieno", nil] opere e scende l'intera produzione SYS Profiler nella finestra della console.

Qualche consiglio sul perché questo non funziona o come implementare meglio questo? Sto cercando di non utilizzare uno script di shell o AppleScript per ottenere il profiler del sistema. Se il lavoro non c'è niente di questo sarebbe la mia ultima opzione. Grazie in anticipo.

È stato utile?

Soluzione 2

Questa ottenuto farlo fare (grazie a Peter e Costique)

[taskDebug setLaunchPath: @"/usr/sbin/system_profiler"];    
NSArray *args = [NSArray arrayWithObjects:@"-xml",@"-         detailLevel",@"full",nil];


[taskDebug setArguments:args];

[[NSFileManager defaultManager] createFileAtPath: [pathToFile stringByExpandingTildeInPath] contents: nil attributes: nil];

outFile = [ NSFileHandle fileHandleForWritingAtPath:[pathToFile stringByExpandingTildeInPath]];

[taskDebug setStandardOutput:outFile];
[taskDebug launch];

Altri suggerimenti

NSArray *args = [NSArray arrayWithObjects:@"-xml",@"-detailLevel",@"full",@">", @"~/Desktop/Profiler.spx",nil];

che non funziona perché non si passa attraverso il guscio, e > è un operatore di shell. (Inoltre, ~ non è speciale, tranne quando si espande utilizzando stringByExpandingTildeInPath.)

Crea un NSFileHandle per la scrittura a quel file Profiler.spx, avendo cura di utilizzare il percorso assoluto completo, non il percorso tilde-abbreviato. Poi, set che NSFileHandle come del task standard output . Questo è essenzialmente ciò che la shell fa quando si utilizza un operatore > in esso.

Crea un NSPipe, inviare [taskDebug setStandardOutput: miapipe]. E leggere dal file handle del pipe

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top