将带引号的字符串参数传递给 msys 脚本中的 java
我一直在尝试在Windows机器上的msys中从bash脚本运行一些java程序。具体来说,我在命令行上使用 WEKA 自动执行一些任务。我遇到一些问题,带引号的字符串未正确传递给 java.lang.实际的代码循环运行一系列命令。这是一个精简版本,即单次迭代,其中 $RUN
包含数组元素字符串。
#!/bin/bash
export CLASSPATH=CLASSPATH:weka.jar:libsvm.jar
RUN="java weka.classifiers.functions.LibSVM -S 0 -K 2 -D 3 -G 0.0 -R 0.0 -N 0.5 -M 1000.0 -C 1000000.0 -E 0.0010 -P 0.1 -Z -W '1 2' -t trainFile.csv -T testFile.csv "
# does not work, returns => Weka exception: For input string: "'1"
$RUN > reportFile.txt
RUN="java weka.classifiers.functions.LibSVM -S 0 -K 2 -D 3 -G 0.0 -R 0.0 -N 0.5 -M 1000.0 -C 1000000.0 -E 0.0010 -P 0.1 -Z -W \"1 2\" -t trainFile.csv -T testFile.csv "
# does not work, returns => Weka exception: For input string: ""1"
$RUN > reportFile.txt
RUN="java weka.classifiers.functions.LibSVM -S 0 -K 2 -D 3 -G 0.0 -R 0.0 -N 0.5 -M 1000.0 -C 1000000.0 -E 0.0010 -P 0.1 -Z -t trainFile.csv -T testFile.csv "
# works without the string argument for -W
$RUN > reportFile.txt
看来问题是字符串 "1 2"
被分成两个参数。如何将它们合并为一个论点?
我正在使用 Windows 7、msys
和 mintty
终端。
I have been trying to run some java programs from a bash script in msys on a windows machine. Specifically, I am automating some tasks using WEKA on command line. I have some problems where a quoted string is not passed correctly to java. The actual code loops through an array of commands to run. Here is a stripped down version, i.e. a single iteration where $RUN
contains the array element string.
#!/bin/bash
export CLASSPATH=CLASSPATH:weka.jar:libsvm.jar
RUN="java weka.classifiers.functions.LibSVM -S 0 -K 2 -D 3 -G 0.0 -R 0.0 -N 0.5 -M 1000.0 -C 1000000.0 -E 0.0010 -P 0.1 -Z -W '1 2' -t trainFile.csv -T testFile.csv "
# does not work, returns => Weka exception: For input string: "'1"
$RUN > reportFile.txt
RUN="java weka.classifiers.functions.LibSVM -S 0 -K 2 -D 3 -G 0.0 -R 0.0 -N 0.5 -M 1000.0 -C 1000000.0 -E 0.0010 -P 0.1 -Z -W \"1 2\" -t trainFile.csv -T testFile.csv "
# does not work, returns => Weka exception: For input string: ""1"
$RUN > reportFile.txt
RUN="java weka.classifiers.functions.LibSVM -S 0 -K 2 -D 3 -G 0.0 -R 0.0 -N 0.5 -M 1000.0 -C 1000000.0 -E 0.0010 -P 0.1 -Z -t trainFile.csv -T testFile.csv "
# works without the string argument for -W
$RUN > reportFile.txt
It seems the the problem is the string "1 2"
is broken into two arguments. How can they be combined into one argument?
I am using Windows 7, msys
with the mintty
terminal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这个解决方法:
Try this workaround: