September 24, 201510 yr Newbies Hello all, I am trying to get the output from RunShellScript: If I load the scriptmaster demo database on my server and from a web browser connection go to the scriptmaster database and load the script "Run Shell Script" put in the desired cmd and click "Run Script" the expected results are returned. To my understanding the "Run Script" button basically will call EvaluateGroovy( demo::script ). So I then copy the code in demo::script to a field in my production database (i.e. prod:script) Then from my production database I call EvaluateGroovy( prod:script ). The function does not return an error, it returns nothing. Other scriptmaster function calls are working on my production database. Below is a screenshot of demo:script with the expected result below after clicking "Run Script ^ R" Below is the actual groovy code I want to run (as shown above in demo::script). I will set this in a variable say $$ShellScript Then in my prod database make a call to EvaluateGroovy ( $$ShellScript ). Nothing is returned. Any help is appreciated. String[] cmds; cmds = ['cmd.exe', '/C', 'dsquery user domainroot -samid yrdhall1* | dsget user -email']; StringBuffer stdout;InputStream inputStream;Process process; ProcessBuilder procBuilder = new ProcessBuilder(cmds);procBuilder.redirectErrorStream(true);process = procBuilder.start(); inputStream = process.getInputStream();stdout = new StringBuffer(); if( Boolean.valueOf( 'true' ) ) { //Wait for command to finish Thread stdoutThread = new Thread( 'stdout reader' ) { public void run() { try { Reader r = new InputStreamReader( inputStream, 'utf-8' ); char[] buff = new char[1024]; int charsRead; while( ( charsRead = r.read( buff ) ) != -1 ) { stdout.append( buff, 0, charsRead ); } } catch( IOException e ) { throw new RuntimeException( e ); } catch ( InterruptedException e) { throw new RuntimeException ( e ); } } }; try { stdoutThread.start(); }catch (RuntimeException e) { throw e; } final int timeoutMilliseconds = Integer.valueOf( '10' ) * 1000; if( timeoutMilliseconds > 0 ) { final Thread mainThread = Thread.currentThread(); new Thread('timeout thread') { public void run() { try { Thread.sleep( timeoutMilliseconds ); process.destroy(); Thread.interrupt(); mainThread.interrupt(); } catch( InterruptedException e ) { //process.destroy(); throw e; } } }.start(); } try { if (process.waitFor() == 0) { stdoutThread.join(); //Wait for all output to be read return stdout.toString(); } else { stdoutThread.join(); //return stdout.toString(); throw new RuntimeException('Process was terminated.'); } } catch( InterruptedException e ) { throw new RuntimeException('Process was interrupted; error output is: ' ); } catch( RuntimeException e ) { //return stdout.toString(); throw e; }} else { //Don't wait, return immediately inputStream.close(); return 'Executed shell command: ' + command;}
Create an account or sign in to comment