cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
matteo_patelmo
Level IV

Files on network

Hello, I have a script which opens a certain file on a network address.  When the computer is connected to that network, everything is ok. But when the computer is offline, I'd like the script to halt gently, instead of waiting and waiting before it understands the address is not available. Is there a function to check quickly the remote file availability or even better the network connection availability?

 

thanks

Matteo

1 ACCEPTED SOLUTION

Accepted Solutions
matteo_patelmo
Level IV

Re: Files on network

Thanks, I will explore this possibility. Actually my resource is a file on a network disk, so ping is not exactly the command I need to use, but the concept of calling a OS command is clear.

 

Matteo

View solution in original post

9 REPLIES 9

Re: Files on network

Hi Matteo,

 

have you tried the TRY and/or the THORW function. They can catch if you cannot find the file and jump out. Not sure if this solves the issue you described as it probably will search for the path as well. However, worth a try if you haven't checked that so far.

 

Martin

/****NeverStopLearning****/

Re: Files on network

e.g. similar to the following command, this will throw an exception message or number if it fails. Then you can do something else (message, alternative file, ...). You may also find other tips in this thread: Can-JMP-call-a-DOS-Exe

a = Try( Open( networkpath ),0 )
/****NeverStopLearning****/
matteo_patelmo
Level IV

Re: Files on network

thanks Martin. Yes I'm using "try", but when I'm not connected to the network it takes about 10seconds before exiting.

 

Matteo

Re: Files on network

ok, then you might want to use a system command to check if the network connection is available and call it before you execute the rest of the script. Not sure if that would last less time though. Some ideas are written in the post I mentioned before. 

/****NeverStopLearning****/
David_Burnham
Super User (Alumni)

Re: Files on network

Perhaps try checking the presence of the file using File Exists before trying to open it?

-Dave
matteo_patelmo
Level IV

Re: Files on network

Hi Dave, I tried it but it still takes many seconds if resource is not available.

 

thanks

Matteo

Craige_Hales
Super User

Re: Files on network

this script uses ping to get an echo back from a server; the text from ping might be a little different on various OS flavors and the test for "Received = 1" might need adjusting. n=1 means only ping once, w=100 means don't wait more than 100ms.  The mac version will be different, this is (barely) tested on windows.

Ping is named after the sound submarine sonars make...then listen for the echo. But unlike a real echo, other delays are possible with busy computers. Your ping might easily pass through five or more computers, and the echo will be similar.  You can play with ping in a "dos box" like this:

Using ping in a "dos box"Using ping in a "dos box"

   
isAvailable = Function( {resource},
	{default local},
	Contains( RunProgram( executable( "ping" ), options( {"-n 1 -w 100", resource} ), readfunction( "text" ) ), "Received = 1" ) != 0
);

// this succeeds in < .1 second
start = Tick Seconds();
jmp = isAvailable( "jmp.com" );
stop = Tick Seconds();
Show( jmp, stop - start );

// this fails in about 3 seconds
start = Tick Seconds();
fileserver = isAvailable( "jmpsserver" ); // leave out the back slashes and use the first name
stop = Tick Seconds();
Show( fileserver, stop - start );

// this fails in about .2 seconds
start = Tick Seconds();
nonesuch = isAvailable( "x" || Char( Random Integer( 1e15, 9e15 ) ) || ".com" );
stop = Tick Seconds();
Show( nonesuch, stop - start );

jmp = 1; -- jmp.com works
stop - start = 0.0333333333255723;
fileserver = 0; -- that isn't our file server name
stop - start = 2.26666666672099;
nonesuch = 0; -- that isn't likely to be a real web name
stop - start = 0.0500000000465661;

Craige
matteo_patelmo
Level IV

Re: Files on network

Thanks, I will explore this possibility. Actually my resource is a file on a network disk, so ping is not exactly the command I need to use, but the concept of calling a OS command is clear.

 

Matteo

Craige_Hales
Super User

Re: Files on network

try ping with the network disk; that is the middle example. I can't test it completely without asking someone to turn a drive off...

Craige