 |
 |
Launching processes from Java Cocoa
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 2000
Status:
Offline
|
|
I'm working on a project that requires root permissions to change a configuration file. I seem to have hit a wall, and was wondering if anyone could give me some pointers.
I intend to make changes to the config file by su'ing to root from within my app and using sed and awk to make the changes.
I figured out how to authenticate users after looking at Gavin's code, reading the ObjC docs for NIInterface, and poking around in JavaBrowser.
This knowledge does me absolutely no good if I can't launch external processes.
Ideas? I figured as a worse case scenario, I could write a class in ObjC that uses NSTask to do what I need, and work with it across the bridge. This seems to be a suboptimal solution though. I'm also not sure how healthy using two different thread models would be.
If anyone is wondering what all this nonsense is for, I'm trying to write a GUI config program for The Internet Junkbuster ( http://www.junkbuster.com ) and need write access to the config file and blocklist.
Thanks in advance
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status:
Offline
|
|
|
|
|
You can take the dude out of So Cal, but you can't take the dude outta the dude, dude!
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 2000
Status:
Offline
|
|
Thank you once again Gavin.
I've been quite disgusted with the Java interfaces to Cocoa in the past few days. I think I'm going back to Objective C. Maybe I'll try Java again when the documentation gets a little better. Come to find out the answer to my question was really, really simple.
Code:
/* Code taken from Nicer by Ryan Stevens */
Process p = Runtime.getRuntime().exec(niceit+nval+" "+pid);
Terry
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Oct 2000
Location: Pasadena, CA, USA
Status:
Offline
|
|
> /* Code taken from Nicer by Ryan Stevens */
> Process p = Runtime.getRuntime().exec(niceit+nval+" "+pid);
Though there are reasons to be annoyed with the Java2ObjC bridge (I've had my share of problems with the bridge) but this little snippet of code shouldn't be one of them - it's pure Java. It'll even work under OS 9 for some commands.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 2000
Status:
Offline
|
|
I got a crash course in Runtime today. After looking at Ryan's code for Nicer, I found some things I wanted to change. I learned quite a bit while modifying the code to launch "/usr/bin/su root -c somecommand". Thanks for the comments people. I think I've got it figured out.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status:
Offline
|
|
Before you get real annoyed with Runtime.exec() - which is certainly a possibility - you may want to read this article in JavaWorld which details some of the irregularities with the API. E.G., external processes hanging because of the stdin/out/err buffers, command parsing, etc.
http://www.javaworld.com/javaworld/j...229-traps.html
------------------
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status:
Offline
|
|
One more thing, it may be easier for you to create a shell script and then use Runtime.exec("sh " + path_to_shell_script) and do all the processing in the more comfortable (and more testable) shell environment.
------------------
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
I've tried using this method before and even though it appeared to compile and execute - nothing happened as was supposed to. Maybe not too reliable.
NSTask seems overcomplex so I never tried it out.
------------------
Think Different.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|