Beginner
Date of registration: Jan 15th 2011
Location: Sarasota, FL
Occupation: Cabinet Design
Hobbies: Programming
This post has been edited 1 times, last edit by "Perry" (Jul 29th 2013, 7:25pm)
Beginner
Date of registration: Jan 15th 2011
Location: Sarasota, FL
Occupation: Cabinet Design
Hobbies: Programming
Source code |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * A Java method to execute and wait for a shell command to complete */ public class JavaShellExecute { public static void main(String[] args) throws Exception { runShellCommand("open somefile.txt", true); } /** * The OPEN command on MacOSX causes the registered file handler to open a file. * The START command on Windows causes the registered file handler to open a file. * * Example param can include a path and file such as: * "open yourpath/somefile.txt" */ public static void runShellCommand(String shellCommand, boolean printShellOutput) throws IOException, InterruptedException { Runtime runtime = Runtime.getRuntime() ; Process shellProcess = runtime.exec(shellCommand) ; //Only wait for if you need the external app to complete shellProcess.waitFor() ; //You can read the contents of the application's information it is writing to the console BufferedReader shellCommandReader = new BufferedReader( new InputStreamReader(shellProcess.getInputStream() ) ) ; String currentLine = null; while ( (currentLine = shellCommandReader.readLine() ) != null ) { if (printShellOutput) System.out.println(currentLine); } } } |
Beginner
Date of registration: Jan 15th 2011
Location: Sarasota, FL
Occupation: Cabinet Design
Hobbies: Programming
Source code |
|
1 2 3 4 5 6 7 8 9 10 11 |
Dim FN as String,SN as String Dim ShellExecute As java#lang#Runtime = Java#lang#Runtime.getRuntime ' *** This below is Dimmed for future error checking *** Dim IOP As Java#lang#Process = Java#lang#Process Dim IOE As java#io#BufferedReader = Java#io#BufferedReader FN = "H:\Library\Filename.rtf" SN = "start " & FN Debug.Print SN ShellExecute.exec(SN) |
Source code |
|
1 2 3 4 |
FN = "H:\Library\Filename.rtf" SN = Chr(34) & "start " & FN & Chr(34) Debug.Print SN ShellExecute.exec(SN) |
Source code |
|
1 2 3 4 |
FN = "H:\Library\Filename.rtf" SN = FN Debug.Print SN ShellExecute.exec(SN) |
This post has been edited 1 times, last edit by "Perry" (Aug 5th 2013, 1:40pm)
Jabaco Source |
|
1 |
Shell "notepad C:\textfile.txt" |
Jabaco Source |
|
1 |
Shell "cmd /c start C:\textfile.txt" |
Beginner
Date of registration: Jan 15th 2011
Location: Sarasota, FL
Occupation: Cabinet Design
Hobbies: Programming
Beginner
Date of registration: Jan 15th 2011
Location: Sarasota, FL
Occupation: Cabinet Design
Hobbies: Programming
Source code |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Public Sub ShellExec(FN As String) Dim p As java#lang#Process Dim input As java#io#InputStream Dim cdata As java#lang#Character Dim data As Integer p = Shell("cmd /c start " & FN) input = p.getInputStream data = input.read While data <> -1 cdata = Cast(data, java#lang#Character) data = input.read Wend input.close p.destroy End Sub |
Right.A question then.
I don't have access to a MAC.
I assume that your implementation is for a MS OS
Quoted
Is it implemented on a Mac the same way?
How about Linux and Unix OS?
Anybody try this on other operating systems?
Thanks much. It works well in MS Windows and I understand from your thread it will work at least in Linux as well.
Jabaco Source |
|
1 |
Runtime.getRuntime().exec(shellCommand); |
Jabaco Source |
|
1 |
Shell(shellCommand) |
Jabaco Source |
|
1 |
cmd /c start textfile.txt |
Beginner
Date of registration: Jan 15th 2011
Location: Sarasota, FL
Occupation: Cabinet Design
Hobbies: Programming
Quoted
So, if you want to be sure, that you can edit an textfile from every platform, then write your own texteditor in Java or using an external texteditor written for the JVM.