壳牌(庆典)括号扩展Java的的Runtime.exec [英] Shell (bash) brace expansion with Java's runtime.exec
问题描述
我试图得到一个扩展命令的Runtime.exec工作,但括号正在PTED为文字而不是扩大跨$ P $。这里就是我想要做的:
I'm trying to get an expansion command to work with runtime.exec, but the braces are being interpreted as literals rather than being expanded. Here's what I'm trying to do:
String command = "mkdir -p Foldername{1,2,3}/InnerFolder";
Runtime.getRuntime().exec( new String[] { "sh", "-c", command } );
不幸的是,这给了我在我的当前目录的单个文件夹名为文件夹名{1,2,3}的Foldername1,Foldername2和Foldername3代替。有谁被间preTED字面知道的方式,以prevent括号?
Unfortunately, that gives me a single folder in my current directory named "Foldername{1,2,3}" instead of "Foldername1", "Foldername2", and "Foldername3". Does anyone know of a way to prevent the braces from being interpreted as literals?
推荐答案
您正在尝试使用通配符猛砸。他们是Bash shell中PTED内跨$ P $。您可以直接运行的mkdir,所以没有壳间preT {}
。你需要指定的shell路径
You're trying to use Bash wildcards. They are interpreted within the Bash shell. You are running mkdir directly, so there is no shell to interpret {}
. You need to specify path to the shell
String command = "mkdir -p Foldername{1,2,3}/InnerFolder";
Runtime.getRuntime().exec( new String[] { "/bin/bash", "-c", command } );
<一个href=\"http://stackoverflow.com/questions/2111983/java-runtime-getruntime-exec-wildcards\">Source.
这篇关于壳牌(庆典)括号扩展Java的的Runtime.exec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!