Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 4884 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

So I run this command


RunShellScript( "ping google.com" ; "true"; 30 )




It works just fine



I wait 30 seconds and run it again...



It returns "ERROR". The LastError returns this...



java.lang.RuntimeException: Process was interrupted; error output is: 




This always happens about 30 seconds after I run the command the first time. I wrote a script that ran that command once every second and it always fails in 32 seconds. Anyone have any ideas? I'm running Windows 7 64-bit.



Also if I run the same command but set the timeout to 10 the same thing happens 10 seconds later so it stops working for as many seconds as the timeout is set to.



Im using this code, I havnt changed it from the scriptmaster file...




boolean isMac = System.getProperty("os.name").contains("Mac");

String[] cmds;

//if( isMac ) cmds = new String[] {"/bin/sh", "-c", command};

//else cmds = new String[] {"cmd.exe", "/C", command};

if( isMac ) cmds = ["/bin/sh", "-c", command];

else cmds = ["cmd.exe", "/C", command];



final Process process = Runtime.getRuntime().exec( cmds );

final InputStream inputStream = process.getInputStream();

final InputStream errorStream = process.getErrorStream();



final StringBuffer stdout = new StringBuffer();

final StringBuffer stderr = 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, "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 );

			}

		}

	};

	stdoutThread.start();



	Thread stderrThread = new Thread( "stderr reader" ) {

		public void run() {

			try {

				Reader r = new InputStreamReader( errorStream, "utf-8" );

				char[] buff = new char[1024];

				int charsRead;

				while( ( charsRead = r.read( buff ) ) != -1 ) {

					stderr.append( buff, 0, charsRead );

				}

			} catch( IOException e ) {

				throw new RuntimeException( e );

			}

		}

	};

	stderrThread.start();



	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 );

					mainThread.interrupt();

				} catch( InterruptedException e ) {

					//Ignore

				}

			}

		}.start();

	}

	try {

		if( process.waitFor() == 0 ) { //Successful

			stdoutThread.join(); //Wait for all output to be read

			return stdout.toString();

		} else { //Error when running command

			stderrThread.join(); //Wait for entire error message to be read

			throw new RuntimeException( stderr.toString() );

		}

	} catch( InterruptedException e ) {

		throw new RuntimeException("Process was interrupted; error output is: " + stderr.toString() );

	}

} else { //Don't wait, return immediately

	inputStream.close();

	errorStream.close();

	return "Executed shell command: " + command;

}

Posted

Another note.... It will do the same thing on Windows XP. When you close filemaker and open it again the command starts working again, but fails again in the same way.

Posted

The ping command runs until you cancel it, so it's never going to return anything. If you try typing "ping google.com" in your shell on your computer you will see that it runs until you hit control-c to cancel the command. It never finishes and returns anything and it doesn't end. You've set the module to time out after 30 seconds, and so it runs ping for 30 seconds and then times out as the ping command doesn't end on its own. When you set it to 10 seconds it just times out sooner.

Posted

The ping command runs until you cancel it, so it's never going to return anything. If you try typing "ping google.com" in your shell on your computer you will see that it runs until you hit control-c to cancel the command. It never finishes and returns anything and it doesn't end. You've set the module to time out after 30 seconds, and so it runs ping for 30 seconds and then times out as the ping command doesn't end on its own. When you set it to 10 seconds it just times out sooner.

That is not true. when you type in "RunShellScript( "ping google.com"; "true" ; 10)" you get this....

Pinging google.com [74.125.225.51] with 32 bytes of data:

Reply from 74.125.225.51: bytes=32 time=25ms TTL=54

Reply from 74.125.225.51: bytes=32 time=24ms TTL=54

Reply from 74.125.225.51: bytes=32 time=36ms TTL=54

Reply from 74.125.225.51: bytes=32 time=23ms TTL=54

Ping statistics for 74.125.225.51:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 23ms, Maximum = 36ms, Average = 27ms

by default it stops after 4 pings. This command works the first time just fine and keeps working until the amount of time since the first time I ran it is greater than the timeout. The problem I'm having is that If I run that same command again it returns "ERROR" until I restart Filemaker.

Another thing I noticed is that when you run this inside the scriptmaster file in the edit script page this problem dosnt happen but when you run it as a command in the data viewer the problem happens.

Posted

Am I just using the function incorrectly? Do I need to put something in the code that will quit out the session so I may run the command again? I want to do two things with this function, I want to run tasklist.exe to see if a process is running and I want to ping a website to make sure the internet is working before I run a script. Even running tasklist.exe causes the problem, would that not run in a loop and quit out by its self?

Posted

I wouldn't recommend running the function in the data viewer. The data viewer can do some strange refreshing that may be causing the command to run over and over and may be causing problems. I've done some testing on this and you're right that it does end after four pings on windows 7. It seems like it runs fine when you call it in a script the normal way, correct?

Posted

I wouldn't recommend running the function in the data viewer. The data viewer can do some strange refreshing that may be causing the command to run over and over and may be causing problems. I've done some testing on this and you're right that it does end after four pings on windows 7. It seems like it runs fine when you call it in a script the normal way, correct?

I was running this in the data viewer by hitting the "evaluate now" button, I did not hit the "monitor" button which would cause it to run over and over. I also ran this as a "set variable" step in a script. The only way I can get this to work is if I run it in the script master file by hitting the "Run Script" Button but when I try to run it as a function by its self is when the problem happens.

Posted

No, I'm not able to reproduce this when I run the module in a script. The data viewer has problems running scripts like this because it has some unique behaviors, and I don't recommend running it in the data viewer at this time.

Are you experiencing issues running this in a normal Set Variable, Set Field, or other script step?

Posted

What I did was I downloaded the latest version of scripmaster and opened the included FileMaker file. I set the function to register at start up and I made this script...

one.png

then I ran the script and got this...

two.png

Then I waited 10 seconds and ran it again....

three.png

Will the same thing work for you?

Posted

I got the same error. There may be a problem in the module. I'm going to have someone check into this, but I can't say for sure when we'll have an answer for you. Thank you for giving me a reproducible case to work with.

Posted

While this not an answer to your question about why this module is not working, it may provide a work-around.

The first few results from this search seemed to give decent advice on how to test connection to a website through java: http://www.google.ca/search?sourceid=chrome&ie=UTF-8&q=java+test+if+connected+to+internet

Getting a task list from java doesn't seem quite as easy, but you may be able to find some useful information with a search like: http://www.google.ca/search?sourceid=chrome&ie=UTF-8&q=java+tasklist

This topic is 4884 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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