Package Torello.Java
Class MSDOS
- java.lang.Object
-
- Torello.Java.OSCommands
-
- Torello.Java.MSDOS
-
- All Implemented Interfaces:
java.lang.Cloneable
public class MSDOS extends OSCommands implements java.lang.Cloneable
This Class ExtendsOSCommands
:
ClassOSCommands
is the parent class for all classes which invoke Operating-System Processes using the Java-Standardjava.lang.Process
Object-Utility.OSCommands
has several constructors inherited by this class which allow a user to configure this class for sending its output in any number of ways toAppendable
instances / loggers of your choice. Read this class documentation about invoking a constructor using any number of log-configurations, for sending text-output to any neccessary destination.
All Methods ReturnOSResponse
:
In addition to real-time process-output printing, this class will collect any all text sent to Standard-Output and Error-Output and save theString
-data for return to the user. All Operating-System calls in this class (which are all invoked by these methods, below) will always return an instance ofOSResponse
.
ClassOSResponse
also contains the fieldresponse
, which signals what the OS-Process' return-value was. Operating-Systems, generally, return a'0'
to indicate the process ran to completion without errors, and some other value to signal an error occurred.
ClassOSExtras
has All Additionaljava.lang.Process
Features:java.lang.Process
allows a user to redirect output, and collect-input to and from any number of additional sources. There is copious documentation aboutOSExtras
, explaining these features.
To specialize an Operating-System call with anOSExtras
instance, just call this class'setOSExtras(...)
method, with any neccessary configurations.A great tool for invoking commands to an MS-DOS operating-system. Allows a straight-forward way to make simple command-line / operating-system calls to an Microsoft DOS terminal.
WORA:
In its inception, Java made the "Write Once, Run Anywhere" (WORA) pledge. The methods in this class are not in any way "Java-ized" versions of the Operating System Calls. Rather, they are just wrappers aroundjava.lang.Process
allowing a user to BOTH make Operating System calls easily AND to efficiently retrieve the generated text-output produced by the calls.
The bulk-work of the classes in this JAR Library were written and tested in a UNIX environment. While everything in the HTML Package ofJava HTML JAR
is indeed, O/S Independent (adhering to 'WORA'), this class and all classes which extendOSCommands
are highly O/S dependent. The methods in these classes are (for all intents and purposes) a set of hooks into native Operating System calls.
This means that an invocation of these methods while running in the wrong Operating System will just return a bunch of error-output results and thrown exceptions.
Synchronized Methods:
The vast majority of the methods in classOSCommands
are synchronized. Specifically, the methods are declared using the Java Key-Wordsynchronized
(even though Java Doc doesn't output that particular word into its method declarations). This also means that all classes extending and inheritingOSCommands
will all have Thread-Safe andsynchronized
methods.
Whenever a command is issued to this class, execution control for the current thread will not proceed / continue until the external operating system process has finished What that does mean, is that if this class were used by two different threads inside of a multi-threaded application, only one thread would ever be allowed to use this class. If you have a program that needs more than one thread making O/S calls, simply construct a second instance of this class (one for each thread), and any 'locking problems' should be resolved.
Wild Cards:
The behavior of expanding an'*'
or'?'
is another somewhat Operating-System Dependent phenomenon. It may be the case that Wild-Cards are expanded by the Operating-System, before the call. In such scenarios, when Java makes a call to the O/S it must have expanded its Wild-Cards.- See Also:
OSCommands
,OSResponse
Hi-Lited Source-Code:- View Here: Torello/Java/MSDOS.java
- Open New Browser-Tab: Torello/Java/MSDOS.java
-
-
Field Summary
-
Fields inherited from class Torello.Java.OSCommands
appendable, cmdOrCmdAndOutput, errorOutput, osExtras, printCmdAppendable, standardOutput
-
-
Constructor Summary
Constructors Constructor MSDOS()
MSDOS(Appendable appendable, boolean cmdOrCmdAndOutput, Appendable printCmdAppendable)
MSDOS(Appendable appendable, boolean cmdOrCmdAndOutput, Appendable printCmdAppendable, Appendable standardOutput, Appendable errorOutput)
MSDOS(Appendable standardOutput, Appendable errorOutput)
-
Method Summary
Copying Files Modifier and Type Method OSResponse
COPY(String[] src, String target)
OSResponse
COPY(String src, String target)
OSResponse
COPY(Vector<String> src, String target)
Deleting Files Modifier and Type Method OSResponse
DEL(String s1)
OSResponse
DEL(String[] sArr)
Methods: interface java.lang.Cloneable Modifier and Type Method MSDOS
clone()
-
Methods inherited from class Torello.Java.OSCommands
appendable, commandToString, equals, errorOutput, printAndRun, printCmdAppendable, run, run, setAll, setAppendable, setOSExtras, setStandardAndErrorOutput, standardOutput, toString
-
-
-
-
Constructor Detail
-
MSDOS
public MSDOS()
Default constructor for instances inheriting this class. This constructor assigns the default values to all of the output loggingAppendable's
. This constructor's "See Also" section has a link to each of the loggingAppendable's
provided by this class.
Note that all of them are assigned 'null' - meaing their output will not be logged - except for the primary fieldthis.appendable
. This field is assignedSystem.out
, meaning that all text output by a process will be sent to the terminal window.
Description copied in entirety from:OSCommands()
- See Also:
OSCommands()
- Code:
- Exact Constructor Body:
super();
-
MSDOS
public MSDOS(java.lang.Appendable appendable, boolean cmdOrCmdAndOutput, java.lang.Appendable printCmdAppendable)
This constructor allows a user to assign theAppendable's
:appendable
&printCmdAppendable
.
The first collects all text-output generated by the processes and prints it using theAppendable's
printing methods. This includes text generated for BOTHStandard-Output
ANDError-Output
. This text is collected in real time as it is output by the underlying process.
The secondAppendable
merely accepts the requested command, itself, as an outputString
. ThisString
is printed using theAppendable's
append(...)
methods.
NOTE: Either of theseAppendable's
may be assigned null, and if they are, they are simply ignored.NullPointerException
won't throw, and the output text will simply not be printed.
Description copied in entirety from:OSCommands(Appendable, boolean, Appendable)
- Parameters:
appendable
- This parameter's reference is assigned directly to theOSCommands
field:appendable
. To clearly understand the use of this field, please review the documentation linked for that field. To summarize, thejava.lang.Appendable
that is synonymously namedappendable
simply collects all output text generated by a processes as it executes, and sends it to the reference'sappend(...)
method. This text will include that sent to BOTHStandard-Output
AND text sent toError-Output
. The text that is printed is transmitted in the order it is received from the reader-threads that read the underlying process' text-pipes.
By default this parameter is assignedSystem.out
. When this default value is used, it means that as the process executes, any and all text it prints is sent to the UNIX or MS-DOS Operating System Terminal Window.
This field may be assigned null, and when so it is just ignored. Assigning null toappendable
. will not produce aNullPointerException
.cmdOrCmdAndOutput
- Thisboolean
is assigned to theOSCommands
field namedcmdOrCmdAndOutput
.
Please review the documentation for that field to understand clearly the use of this parameter.printCmdAppendable
- Thisjava.lang.Appendable
allows for yet another output mechanism when executing operating system commands. The sole purpose of thisAppendable
is to print the process command, itself, as a JavaString
- exactly as it was issued to the operating system.
This allows a type of "Monitor Log" to store all commands being issued to the Operating-System, without having to include the full-text output that those process calls have produced. The value passed to this parameter is assigned to theOSCommands
field namedprintCmdAppendable
.
This parameter may be null, and if it is, no such output will be generated.- See Also:
OSCommands.appendable
,OSCommands.cmdOrCmdAndOutput
,OSCommands.printCmdAppendable
,OSCommands(Appendable, boolean, Appendable)
- Code:
- Exact Constructor Body:
super(appendable, cmdOrCmdAndOutput, printCmdAppendable);
-
MSDOS
public MSDOS(java.lang.Appendable appendable, boolean cmdOrCmdAndOutput, java.lang.Appendable printCmdAppendable, java.lang.Appendable standardOutput, java.lang.Appendable errorOutput)
Constructor that allows for assigning all four text-collectingAppendable's
. Please review the documentation for each of these fields to understand better how theseAppendable's
may be used.
NOTE: Any of theseAppendable's
may be assigned null, and if they are, they are simply ignored.NullPointerException
won't throw, and the relevant output text that would normally be appended to it, will simply not be appended.
Description copied in entirety from:OSCommands(Appendable, boolean, Appendable, Appendable, Appendable)
- Parameters:
appendable
- This parameter's reference is assigned directly to theOSCommands
field:appendable
. To clearly understand the use of this field, please review the documentation linked for that field. To summarize, thejava.lang.Appendable
that is synonymously namedappendable
simply collects all output text generated by a processes as it executes, and sends it to the reference'sappend(...)
method. This text will include that sent to BOTHStandard-Output
AND text sent toError-Output
. The text that is printed is transmitted in the order it is received from the reader-threads that read the underlying process' text-pipes.
By default this parameter is assignedSystem.out
. When this default value is used, it means that as the process executes, any and all text it prints is sent to the UNIX or MS-DOS Operating System Terminal Window.
This field may be assigned null, and when so it is just ignored. Assigning null toappendable
. will not produce aNullPointerException
.cmdOrCmdAndOutput
- Thisboolean
is assigned to theOSCommands
field namedcmdOrCmdAndOutput
.
Please review the documentation for that field to understand clearly the use of this parameter.printCmdAppendable
- Thisjava.lang.Appendable
allows for yet another output mechanism when executing operating system commands. The sole purpose of thisAppendable
is to print the process command, itself, as a JavaString
- exactly as it was issued to the operating system.
This allows a type of "Monitor Log" to store all commands being issued to the Operating-System, without having to include the full-text output that those process calls have produced. The value passed to this parameter is assigned to theOSCommands
field namedprintCmdAppendable
.
This parameter may be null, and if it is, no such output will be generated.standardOutput
- ThisAppendable
is assigned to the internalOSCommands
field:standardOutput
. ThisAppendabe
, as the name hopefully implies, allows a user to collect any / all text sent by the process toStandard-Output
.
Please review the documentation for that field to better understand it's use. Also, keep in mind that null may be passed to this parameter, and if / when it is the correspondingAppendable
field will simply be ignored during the process execution.errorOutput
- ThisAppendable
is assigned to the internalOSCommands
field:errorOutput
. ThisAppendabe
, as the name hopefully implies, allows a user to collect any / all text sent by the process toError-Output
.
Please review the documentation for that field to better understand it's use. Also, keep in mind that null may be passed to this parameter, and if / when it is the correspondingAppendable
field will simply be ignored during the process execution.- See Also:
OSCommands.appendable
,OSCommands.cmdOrCmdAndOutput
,OSCommands.printCmdAppendable
,OSCommands.standardOutput
,OSCommands.errorOutput
,OSCommands(Appendable, boolean, Appendable, Appendable, Appendable)
- Code:
- Exact Constructor Body:
super(appendable, cmdOrCmdAndOutput, printCmdAppendable, standardOutput, errorOutput);
-
MSDOS
public MSDOS(java.lang.Appendable standardOutput, java.lang.Appendable errorOutput)
This constructor retains all default values for the internal fields of this class, except for the twoOSCommands
Appendable
fields listed, namely:standardOutput
anderrorOutput
Description copied in entirety from:OSCommands(Appendable, Appendable)
- Parameters:
standardOutput
- ThisAppendable
is assigned to the internalOSCommands
field:standardOutput
. ThisAppendabe
, as the name hopefully implies, allows a user to collect any / all text sent by the process toStandard-Output
.
Please review the documentation for that field to better understand it's use. Also, keep in mind that null may be passed to this parameter, and if / when it is the correspondingAppendable
field will simply be ignored during the process execution.errorOutput
- ThisAppendable
is assigned to the internalOSCommands
field:errorOutput
. ThisAppendabe
, as the name hopefully implies, allows a user to collect any / all text sent by the process toError-Output
.
Please review the documentation for that field to better understand it's use. Also, keep in mind that null may be passed to this parameter, and if / when it is the correspondingAppendable
field will simply be ignored during the process execution.- See Also:
OSCommands.standardOutput
,OSCommands.errorOutput
,OSCommands(Appendable, Appendable)
- Code:
- Exact Constructor Body:
super(standardOutput, errorOutput);
-
-
Method Detail
-
clone
public MSDOS clone()
Creates a clone of'this'
instance. Though unlikely of much use, this could conceivably have some function if similar, but non-identical, output mechanisms were being used.- Specified by:
clone
in classOSCommands
- Returns:
- An exact copy of
'this'
instance ofMSDOS
- one in which all outputAppendable's
have had their references copied into the new instance. - Code:
- Exact Method Body:
return new MSDOS( this.appendable, this.cmdOrCmdAndOutput, this.printCmdAppendable, this.standardOutput, this.errorOutput );
-
COPY
public OSResponse COPY(java.lang.String src, java.lang.String target) throws java.io.IOException
MS-DOS Command:COPY
UNIX or DOS Shell Command:
C:\>COPY <src> <target>- Parameters:
src
- MS-DOS'COPY'
command's "source" argumenttarget
- The'COPY'
command's "target" argument- Returns:
- Returns an instance of
OSResponse
. This response-Object
(data-record) class holds threepublic, final
fields:
① Processresponse-code
② Text sent toStandard-Output
(as ajava.lang.String
)
③ Text sent toError-Output
(also as aString
)
ThisOSResponse
instance may be discarded without any effect onProcess
Execution. It is only provided as a convenience in case more information is required about the results of theO/S
command invocation.
Process Status: Upon completion of this method, theOperating-System java.lang.Process
is guaranteed to have run to completion. - Throws:
java.io.IOException
- If there are problems while invoking the operating-system command- See Also:
OSCommands.printAndRun(String[])
- Code:
- Exact Method Body:
String[] command = { "COPY", src, target }; return printAndRun(command);
-
COPY
public OSResponse COPY(java.util.Vector<java.lang.String> src, java.lang.String target) throws java.io.IOException
MS-DOS Command:COPY
UNIX or DOS Shell Command:
C:\>COPY <src.elementAt(0)> <src.elementAt(1)> ... <src.elementAt(src.size()-1)> <target>- Parameters:
src
- This may be a list of files to be copied to a target directorytarget
- This is the target directory for the files listed.- Returns:
- Returns an instance of
OSResponse
. This response-Object
(data-record) class holds threepublic, final
fields:
① Processresponse-code
② Text sent toStandard-Output
(as ajava.lang.String
)
③ Text sent toError-Output
(also as aString
)
ThisOSResponse
instance may be discarded without any effect onProcess
Execution. It is only provided as a convenience in case more information is required about the results of theO/S
command invocation.
Process Status: Upon completion of this method, theOperating-System java.lang.Process
is guaranteed to have run to completion. - Throws:
java.io.IOException
- If there are problems while invoking the operating-system command- See Also:
OSCommands.printAndRun(String[])
- Code:
- Exact Method Body:
String[] command = new String[src.size() + 2]; command[0] = "COPY"; command[src.size() + 1] = target; for (int i=0; i < src.size(); i++) command[1 + i] = src.elementAt(i); return printAndRun(command);
-
COPY
public OSResponse COPY(java.lang.String[] src, java.lang.String target) throws java.io.IOException
MS-DOS Command:COPY
UNIX or DOS Shell Command:
C:\>COPY <src[0]> <src[1]> ... <src[src.length-1]> <target>- Parameters:
src
- This may be a list of files to be copied to a target directorytarget
- This is the target directory for the files listed.- Returns:
- Returns an instance of
OSResponse
. This response-Object
(data-record) class holds threepublic, final
fields:
① Processresponse-code
② Text sent toStandard-Output
(as ajava.lang.String
)
③ Text sent toError-Output
(also as aString
)
ThisOSResponse
instance may be discarded without any effect onProcess
Execution. It is only provided as a convenience in case more information is required about the results of theO/S
command invocation.
Process Status: Upon completion of this method, theOperating-System java.lang.Process
is guaranteed to have run to completion. - Throws:
java.io.IOException
- If there are problems while invoking the operating-system command- See Also:
OSCommands.printAndRun(String[])
- Code:
- Exact Method Body:
String[] command = new String[src.length + 2]; command[0] = "COPY"; command[src.length + 1] = target; for (int i=0; i < src.length; i++) command[1 + i] = src[i]; return printAndRun(command);
-
DEL
public OSResponse DEL(java.lang.String s1) throws java.io.IOException
MS-DOS Command:DEL
UNIX or DOS Shell Command:
C:\>DEL <s1>- Parameters:
s1
- The item to be removed, using an MS-DOS command.- Returns:
- Returns an instance of
OSResponse
. This response-Object
(data-record) class holds threepublic, final
fields:
① Processresponse-code
② Text sent toStandard-Output
(as ajava.lang.String
)
③ Text sent toError-Output
(also as aString
)
ThisOSResponse
instance may be discarded without any effect onProcess
Execution. It is only provided as a convenience in case more information is required about the results of theO/S
command invocation.
Process Status: Upon completion of this method, theOperating-System java.lang.Process
is guaranteed to have run to completion. - Throws:
java.io.IOException
- If there are problems while invoking the operating-system command- See Also:
OSCommands.printAndRun(String[])
- Code:
- Exact Method Body:
String[] command = { "DEL", s1 }; return printAndRun(command);
-
DEL
public OSResponse DEL(java.lang.String[] sArr) throws java.io.IOException
MS-DOS Command:DEL
UNIX or DOS Shell Command:
C:\>DEL <sArr[0]> <sArr[1]> ... <sArr[sArr.length-1]>- Parameters:
sArr
- AnString[] array
which is added to the end of this MS-DOS command. These will be the item(s) removed by the'DEL'
command.- Returns:
- Returns an instance of
OSResponse
. This response-Object
(data-record) class holds threepublic, final
fields:
① Processresponse-code
② Text sent toStandard-Output
(as ajava.lang.String
)
③ Text sent toError-Output
(also as aString
)
ThisOSResponse
instance may be discarded without any effect onProcess
Execution. It is only provided as a convenience in case more information is required about the results of theO/S
command invocation.
Process Status: Upon completion of this method, theOperating-System java.lang.Process
is guaranteed to have run to completion. - Throws:
java.io.IOException
- If there are problems while invoking the operating-system command- See Also:
OSCommands.printAndRun(String[])
- Code:
- Exact Method Body:
String[] command = new String[sArr.length + 1]; command[0] = "DEL"; for (int i=0; i < sArr.length; i++) command[i + 1] = sArr[i]; return printAndRun(command);
-
-