Calling external program with correct permissions
Calling external program with correct permissions
- Subject: Calling external program with correct permissions
- From: Wolfram Stebel <email@hidden>
- Date: Tue, 12 Jul 2005 21:10:25 +0200
Hi all,
to compress images on my Xserve i use ThumbsUp on the (Java) commandline.
This used to work til update 10.4.1.
I think they changed permissions of WO to run on "appserver" only (root
before?) and i get an system message:
"/Applications/Utilities/ThumbsUp/ThumbsUp.app/Contents/MacOS/
ThumbsUp: kCGErrorRangeCheck : Window Server communications from
outside of session allowed for root and console user only"
So i tried the following terrible code (see appendix):
- when i set a password in my properties file, i send the commandline with a
"sudo"
- then i exec the commandline and take the i/o streams of the process to
look for the "Password:" prompt and write the password into the process
- i wait for termination.
So, where is the problem?
As always, in local development, it works (user = admin with correct
permissions).
Locally i get the password prompt via the error stream, in deployment
nothing is received.
After this, in deployment i do not pass the p.waitFor ();
Will Process p be executed as "su" or does the java sandbox stop this?
Is there a known workaround?
Is there another thumbnailer :-) ? I tried ImageMagick, but stopped after
two installations of open source packages and still not running. I'd prefer
a slim solution anyway.
Any tips?
Thanks for your help
Wolfram
---- code snippet ----
String password = NSProperties.getProperty ( "ThumbPassword", "" );
String appLocation = session.application ().getThumbnailerLocation ();
String command = appLocation + outputFilePath;
if ( ( password != null ) && ( password.length () > 0 ) )
command = "sudo " + command;
Process p = Runtime.getRuntime ().exec ( command );
InputStream iS = p.getInputStream();
InputStream eS = p.getErrorStream();
// check if either stream receives any input
int av = iS.available ();
int ev = eS.available ();
int count = ( av > 0 ? av : ev );
if ( count > 0 )
{
// take the stream with data
BufferedReader in = new BufferedReader( new InputStreamReader ( av > 0 ?
iS : eS ) );
StringBuffer b = new StringBuffer ( count );
for ( int l = 0; l < count; l ++ )
b.append ( new Character ( ( char ) in.read () ).toString () );
// check for "sudo" to enter password
if ( b.toString ().equals ( "Password:" ) )
{
OutputStream oS = p.getOutputStream();
oS.write ( password.getBytes () );
oS.flush ();
oS.close ();
}
}
iS.close ();
eS.close ();
int terminated = p.waitFor ();
if ( NSLog.debugLoggingAllowedForLevel ( NSLog.DebugLevelDetailed ) )
{
NSLog.out.appendln ( "Thumbing result: terminated (0=OK) : " +
terminated );
BufferedReader in = new BufferedReader( new InputStreamReader (
p.getErrorStream () ) );
NSLog.out.appendln ( "Thumbing error : " + in.readLine () );
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden