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.

RunCommand module , I wrote

Featured Replies

  • Newbies

Hi,
A Christmas gift.

With minor improvements to "RunShellScript" module in ScriptMaster_16+ sample,
I have wriiten "RunCommand" module.

With a parameter "command" that cantains command and its parameters delimited by Filemaker newline
"¶" s.
, the function run the any command that can run at your computer and get the stdout strings as a return code

examle(case of widows os):
  set variable [ $a = RunCommand( "tasklist¶/nh" ) ] 
or
    set variable [ $a = RunCommand( "cmd¶/c¶dir" ) ]

I use only Windows machines, but perhaps this module will work in Mac environment
You can freely use it at your own risk.

Thank you

source is here
------------------------------------------------------------------------------
String delimitter = '\\u000a';
String encode = "shift-jis";

String[] cmds=command.split( delimitter );
boolean waitForOutput = true;
timeout = 0;
//cmds = [command, params];

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( waitForOutput ) ) { //Wait for command to finish

    Thread stdoutThread = new Thread( "stdout reader" ) {
        public void run() {
            try {
                Reader r = new InputStreamReader( inputStream, encode );
                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( timeout ) * 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;
}
----------------------------------------------------------------------
You can change the encode in 2nd line that you like.

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.