unix - How to run the "screen" command from NSTask? -
i want monitor virtual com port (arduino rfid) on mac. can run "screen /dev/tty.serialnumber" terminal, , outputs rfid serial number when swipe it.
as try xcode nstask following output.
must connected terminal.
here's code:
nstask *cd = [[nstask alloc] init]; [cd setlaunchpath:@"/usr/bin/screen"]; [cd setarguments:[nsarray arraywithobjects:@"-l",@"/dev/tty.usbserial-a800509k",nil]]; nspipe *pipe; pipe = [nspipe pipe]; [cd setstandardoutput: pipe]; [cd setstandardinput:[nspipe pipe]]; nsfilehandle *file; file = [pipe filehandleforreading]; [cd launch]; nsdata *data; data = [file readdatatoendoffile]; nsstring *string; string = [[nsstring alloc] initwithdata: data encoding: nsutf8stringencoding]; nslog (@"%@", string); [cd waituntilexit]; [cd release];
i think you'd better directly access com port, either using foundation libraries, or using third party obj-c libs (for example, https://github.com/pbosetti/pbserialport). also, if want monitor com port, have set thread reading serial port, , updating text area in ui. remember secondary thread should update ui via method - (void)performselector:(sel)aselector onthread:(nsthread *)thr withobject:(id)arg waituntildone:(bool)wait
.
Comments
Post a Comment