阅读背景:

Runtime.getRuntime().exec(command) 如何把多条命令绑在一起执行?

来源:互联网 
命令如下:

type c:
命令如下:

type c:\1.txt | perl c:\mail.pl -s "Subject" -f [email protected] [email protected]"

我需要将上面的内容当作一个整体来运行(就是说把内容都输入到CMD里后,再按回车一起执行)

1. 手动在CMD里输入以上脚本,运行可以达到这个效果。

2. 将上面的内容存放到BAT文件里,Runtime.getRuntime().exec("cmd.exe /k start " + batFile)也可以。

问题来了,当我把该命令定义成一个String,然后Runtime.getRuntime().exec("cmd.exe /k start " + command)

执行效果如下:
type c:\1.txt 回车
| 回车
perl 回车
c:\mail.pl 回车
"Subject" 回车
-f 回车
[email protected] 回车
[email protected] 回车

我的期待效果是:
type c:\1.txt | perl c:\mail.pl -s "Subject" -f [email protected] [email protected] 回车

谁知道是哪里弄错了吗?

3 个解决方案

#1


楼主你的问题都很复杂了

#2


不复杂 不复杂 谁帮帮忙啊

#3


你可以用 &&
c:\1.txt && perl && ................

.txt | perl c:\mail.pl -s "Subject" -f [email protected] [email protected]" type c:
命令如下:

type c:\1.txt | perl c:\mail.pl -s "Subject" -f [email protected] [email protected]"

我需要将上面的内容当作一个整体来运行(就是说把内容都输入到CMD里后,再按回车一起执行)

1. 手动在CMD里输入以上脚本,运行可以达到这个效果。

2. 将上面的内容存放到BAT文件里,Runtime.getRuntime().exec("cmd.exe /k start " + batFile)也可以。

问题来了,当我把该命令定义成一个String,然后Runtime.getRuntime().exec("cmd.exe /k start " + command)

执行效果如下:
type c:\1.txt 回车
| 回车
perl 回车
c:\mail.pl 回车
"Subject" 回车
-f 回车
[email protected] 回车
[email protected] 回车

我的期待效果是:
type c:\1.txt | perl c:\mail.pl -s "Subject" -f [email protected] [email protected] 回车

谁知道是哪里弄错了吗?

3 个解决方案

#1


楼主你的问题都很复杂了

#2


不复杂 不复杂 谁帮帮忙啊

#3


你可以用 &&
c:\1.txt && perl && ................

.txt | perl c:\mail.pl -s 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: