2010-09-09

"Shell" in REALbasic to access command-line

REAL Studio 2010 offers the "Shell" class to call command-line tools.

Any command you would call in the "Terminal" program in Mac OS X or Linux, or the "Command Prompt" program in Windows, you can programmatically call from your REALbasic code. Any text that would otherwise appear at the console in those programs is returned to your code as a String.

Here's a simple example. If you have installed a Java implementation on your computer (already built into Mac OS X), the "java" command on the console will invoke the Java Virtual Machine. Adding "-version" generates a few lines of text describing what version of the Java platform is installed. Executing "java -version" makes a fine demo of the Shell class. Put the following code on a button's Action event handler.


Dim s As New Shell
dim commandLine as String = "java -version"
s.execute (commandLine)
msgbox s.result
s.Close


You should see a dialog like this:

No comments:

Post a Comment