本文整理匯總了Java中org.apache.commons.exec.CommandLine.getArguments方法的典型用法代碼示例。如果您正苦於以下問題:Java CommandLine.getArguments方法的具體用法?Java CommandLine.getArguments怎麽用?Java CommandLine.getArguments使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.exec.CommandLine
的用法示例。
在下文中一共展示了CommandLine.getArguments方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCommandLineAsString
import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
private String getCommandLineAsString( CommandLine commandline )
{
// for the sake of the test comparisons, cut out the eventual
// cmd /c *.bat conversion
String result = commandline.getExecutable();
boolean isCmd = false;
if ( OS.isFamilyWindows() && result.equals( "cmd" ) )
{
result = "";
isCmd = true;
}
String[] arguments = commandline.getArguments();
for ( int i = 0; i < arguments.length; i++ )
{
String arg = arguments[i];
if ( isCmd && i == 0 && "/c".equals( arg ) )
{
continue;
}
if ( isCmd && i == 1 && arg.endsWith( ".bat" ) )
{
arg = arg.substring( 0, arg.length() - ".bat".length() );
}
result += ( result.length() == 0 ? "" : " " ) + arg;
}
return result;
}
示例2: createCommandFile
import org.apache.commons.exec.CommandLine; //導入方法依賴的package包/類
private File createCommandFile(final CommandLine cmd, final Map env)
throws IOException {
File script = File.createTempFile("EXEC", ".TMP");
script.deleteOnExit();
PrintWriter out = null;
try {
out = new PrintWriter(new FileWriter(script.getAbsolutePath(),true));
// add the environment as global symbols for the DCL script
if (env != null) {
Set entries = env.entrySet();
for (Iterator iter = entries.iterator(); iter.hasNext();) {
Entry entry = (Entry) iter.next();
out.print("$ ");
out.print(entry.getKey());
out.print(" == "); // define as global symbol
out.println('\"');
String value = (String) entry.getValue();
// Any embedded " values need to be doubled
if (value.indexOf('\"') > 0){
StringBuffer sb = new StringBuffer();
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (c == '\"') {
sb.append('\"');
}
sb.append(c);
}
value=sb.toString();
}
out.print(value);
out.println('\"');
}
}
final String command = cmd.getExecutable();
if (cmd.isFile()){// We assume it is it a script file
out.print("$ @");
// This is a bit crude, but seems to work
String parts[] = StringUtils.split(command,"/");
out.print(parts[0]); // device
out.print(":[");
out.print(parts[1]); // top level directory
final int lastPart = parts.length-1;
for(int i=2; i< lastPart; i++){
out.print(".");
out.print(parts[i]);
}
out.print("]");
out.print(parts[lastPart]);
} else {
out.print("$ ");
out.print(command);
}
String[] args = cmd.getArguments();
for (int i = 0; i < args.length; i++) {
out.println(" -");
out.print(args[i]);
}
out.println();
} finally {
if (out != null) {
out.close();
}
}
return script;
}