Download or view exectest.frink in plain text format
// This code sample demonstrates starting an external process from Frink,
// capturing its output, (including translating Unicode characters
// from the operating system's encoding,) waiting for it to complete, and
// capturing its exit status. Many of these steps are optional, depending
// on what you're trying to do.
// Use Java introspection to get the Runtime object which will be used to
// create external processes.
runtime = callJava["java.lang.Runtime", "getRuntime", [] ]
// Execute the specified command. Note that there are other versions of
// the Runtime.exec[] method which allow you to pass the working directory and
// environment variables, if you need to.
proc = runtime.exec["/bin/ls -la"]
// Get the input stream (the process's output)
instream = proc.getInputStream[]
// The following lines wrap the InputStream with an InputStreamReader which
// will properly decode Unicode characters in the system's default encoding.
// If the default encoding is not detected, you may need to specify it here.
reader = newJava["java.io.InputStreamReader", [instream]]
// Wrap the reader in a BufferedReader so we can get a readLine function.
bReader = newJava["java.io.BufferedReader", [reader, 32768]]
// Read the output from the process and print it.
while (line = bReader.readLine[])
println[line]
// Wait for the external process to complete
proc.waitFor[]
// Print the exit value of the process.
println["Exit value is " + proc.exitValue[]]
Download or view exectest.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen was born 20203 days, 12 hours, 1 minutes ago.