Execute windows shell command from eBase?

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

EDekker
Ebase User
Posts: 8
Joined: Tue Jun 04, 2013 8:13 am

Execute windows shell command from eBase?

#1

Postby EDekker » Mon Jun 24, 2013 2:47 pm

Hello,

Would it be possible to execute a windows shell command from an eBase script? I'm looking for a way to use Sox ( http://sox.sourceforge.net/ ) to convert .wav files.

Thanks,
Ed
0 x

User avatar
jig
Ebase User
Posts: 30
Joined: Sun Oct 09, 2011 10:16 am
Location: UK

#2

Postby jig » Mon Jun 24, 2013 5:44 pm

Hi Ed,

You can do this by creating and invoking your own Java class (which in-turn executes the cmd/shell command) from an Ebase script.

You have two options for invoking your Java class depending on your Ebase version.

Option 1) Via 'Ebase JavaScript':
a: Import your Java class in Ebase JavaScript and invoke it directly.
OR
b: Create Ebase Custom Resource (Java class) and invoke the same from Ebase JavaScript.

Option 2) Via 'Ebase FPL':
a: Create Ebase Custom Resource (Java class) and invoke the same from Ebase JavaScript.

Hope this helps!

Regards
Jignesh
0 x
Regards,
Jignesh

Jignesh Vaducha, MSc, MCA
Mobile: +44 (0) 77 325 47 112
Telephone: +44 (0) 1462 488 311
Email: jignesh@schnellsolutions.com

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#3

Postby Jon » Tue Jun 25, 2013 8:23 am

You can do this with the Java Runtime class using Javascript on the server. Here is an example of a script that runs the Windows ver command.

Code: Select all

var p = java.lang.Runtime.getRuntime().exec("cmd /C ver");
var stdInput = new java.io.BufferedReader(new java.io.InputStreamReader(p.getInputStream()),8*1024);
var stdError = new java.io.BufferedReader(new java.io.InputStreamReader(p.getErrorStream()));

// read the output from the command
var s = null;
while ((s = stdInput.readLine()) != null)
{ 
	log(s);
}
I got this from StackOverflow via Google. You can convert pretty much any Java code so it can be executed in Javascript. Here's what the original Java code looks like:

Code: Select all

Process p = Runtime.getRuntime().exec("cmd /C ver");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()),8*1024);
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

// read the output from the command
String s = null;
while ((s = stdInput.readLine()) != null)
{ 
   System.out.println(s);
}
To convert to Javascript, you need to:

o Replace the Java object names on the left-hand side of any assignment statements with Javascript "var".
o Add the fully qualified names of all Java classes (or use importPackage statements).
o Change any try/catch statements to Javascript format (there aren't any in this example).

I've also changed the System.out.println() statement to log() to see the output, but this is not a requirement to get it working.

You can use this approach to run pretty much all Java code.

Regards
Jon
0 x

EDekker
Ebase User
Posts: 8
Joined: Tue Jun 04, 2013 8:13 am

#4

Postby EDekker » Wed Jun 26, 2013 8:00 am

Thanks!
0 x


Who is online

Users browsing this forum: No registered users and 5 guests