Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

EvaluateGroovy ("Run Shell Script") failure

Featured Replies

  • 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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.