本文整理汇总了Java中org.apache.commons.exec.environment.EnvironmentUtils.toStrings方法的典型用法代码示例。如果您正苦于以下问题:Java EnvironmentUtils.toStrings方法的具体用法?Java EnvironmentUtils.toStrings怎么用?Java EnvironmentUtils.toStrings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.exec.environment.EnvironmentUtils
的用法示例。
在下文中一共展示了EnvironmentUtils.toStrings方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: launch
import org.apache.commons.exec.environment.EnvironmentUtils; //导入方法依赖的package包/类
/**
* Creates a process with an array of arguments. It seems to be the only
* safe way to create a process with arguments containing spaces. The
* implementation of {@link Runtime#exec(String, String[], File)} doesn't
* appear to process single or double quotes when tokenizing a
* command-line.
*
* @see Runtime#exec(String[], String[], File)
*/
@Override
protected Process launch(CommandLine commandLine, @SuppressWarnings("rawtypes") Map environment,
File workingDirectory) throws IOException {
if (workingDirectory != null && !workingDirectory.exists()) {
throw new IOException(workingDirectory + " doesn't exist.");
}
String[] envVars = EnvironmentUtils.toStrings(environment);
String[] arguments = commandLine.getArguments();
String[] command = new String[arguments.length + 1];
command[0] = commandLine.getExecutable();
System.arraycopy(arguments, 0, command, 1, arguments.length);
return Runtime.getRuntime().exec(command, envVars, workingDirectory);
}
示例2: exec
import org.apache.commons.exec.environment.EnvironmentUtils; //导入方法依赖的package包/类
public Process exec(final CommandLine cmd, final Map env)
throws IOException {
String[] envVar = EnvironmentUtils.toStrings(env);
return Runtime.getRuntime().exec(cmd.toStrings(), envVar);
}
示例3: exec
import org.apache.commons.exec.environment.EnvironmentUtils; //导入方法依赖的package包/类
/**
* Launches the given command in a new process, in the given working
* directory
*
* @param cmd
* the command line to execute as an array of strings
* @param env
* the environment to set as an array of strings
* @param workingDir
* the working directory where the command should run
* @throws IOException
* probably forwarded from Runtime#exec
*/
public Process exec(final CommandLine cmd, final Map env,
final File workingDir) throws IOException {
String[] envVars = EnvironmentUtils.toStrings(env);
return Runtime.getRuntime().exec(cmd.toStrings(),
envVars, workingDir);
}