运行从Java批处理文件时,随机1 - 之前出现的GT;> [英] when running batch file from java , 1 randomly appears before >>
问题描述
我想从我的Java code运行批处理文件
这是批处理文件行:
C:\\用户\\ abdelk \\工作区\\&的Symmetrix GT; symconfigure -sid 13 -cmd创建dev的数量= 16,大小= 139840,仿真为FBA,配置= TDEV;提交-nop>> out_file.txt
当我运行从我的code中的批处理文件,1随机出现之前,>>。所以在CMD线变成这样的:
C:\\用户\\ abdelk \\工作区\\&的Symmetrix GT; symconfigure -sid 13 -cmd创建dev的数量= 16,大小= 139840,仿真为FBA,配置= TDEV;提交-nop ** 1 GT;> ** outfile.txt
我不知道我怎样才能消除这种随机出现的1
这是我从我的code运行批处理文件
rt.exec(CMD.EXE / C启动+ functions_object.edit_host_name(current_host_name)+_ Meta.bat,空,新的文件(C:\\\\用户\\ \\ abdelk \\\\ \\\\工作区项目));
首先,需要对微软的TechNet文章看的使用命令重定向操作符。
数值 1 是手柄等效的标准输出(标准输出)。
在批处理文件中的数字 1 省略对重定向的标准输出
例如把那些2线到一个批处理文件并运行它。
回声这只是一个重定向试验>。CapturedStandardOutput.txt
@暂停
您将看到的cmd.exe
自动插入 1
(空格和1)左重定向操作符方式>
在总体上是不可取的已经加入批处理文件中的 1 对于标准输出
为什么?
外观与执行:
回声这仅仅是一个重定向test.1> CapturedStandardOutput.txt
@暂停
您看到控制台窗口:
回声这仅仅是一个重定向test.1 1> CapturedStandardOutput.txt
和文件的 CapturedStandardOutput.txt 的包含行:
这仅仅是一个重定向test.1
解决方法就是在批处理文件中使用:
回声这只是一个重定向测试。 1> CapturedStandardOutput.txt
这导致了线的执行
回声这只是一个重定向测试。 1> CapturedStandardOutput.txt
和现在有下面的一行在文件的 CapturedStandardOutput.txt 的:
这只是一个重定向测试。
你不能看到这里在浏览器窗口是什么,在文本文件中的行与比较,第一个例子尾随的空间,现在结束。因此,最好是用>
和>>
没有 1 ,否则总是它是不是真的简单的来控制被写入文本文件中。
还有一个提示:
要重定向文本到结尾的文件1,2,...,9有必要向逃跑的数量 ^
。
一个批处理文件的执行
回声号是^ 1 GT; CapturedStandardOutput.txt
@暂停
结果执行命令行
回声号是1 1 GT; CapturedStandardOutput.txt
和文件的 CapturedStandardOutput.txt 的行
数为1
与该行的末尾没有尾随空格。
0 左>
和>>
绝不能逃脱拿到号的 0 写入一个文本文件中。
i am trying to run a batch file from my java code
this is the batch file line :
C:\Users\abdelk\workspace\Symmetrix>symconfigure -sid 13 -cmd "create dev count=16, size=139840, emulation=FBA , config=TDEV;" commit -nop >> out_file.txt
when i run the batch file from my code, "1" randomly appears before the ">>". so line in cmd becomes like that :
C:\Users\abdelk\workspace\Symmetrix>symconfigure -sid 13 -cmd "create dev count=16, size=139840, emulation=FBA , config=TDEV;" commit -nop **1>>** outfile.txt
I don't know how can i remove this random appearing "1"
this is how i run the batch file from my code
rt.exec("cmd.exe /c start "+functions_object.edit_host_name(current_host_name)+"_Meta.bat",null,new File("C:\\Users\\abdelk\\workspace\\Project"));
First, take a look on Microsoft's TechNet article using command redirection operators.
Numeric 1 is an equivalent for handle stdout (standard output).
In batch files numeric 1 is omitted on redirection stdout.
For example put those 2 lines into a batch file and run it
echo This is just a redirect test.>CapturedStandardOutput.txt
@pause
You will see that cmd.exe
automatically inserts 1
(space and 1) left to the redirection operator >
.
In general it is not advisable to add already in batch file 1 for stdout.
Why?
Look what is executed with:
echo This is just a redirect test.1>CapturedStandardOutput.txt
@pause
You see in console window:
echo This is just a redirect test.1 1>CapturedStandardOutput.txt
And the file CapturedStandardOutput.txt contains the line:
This is just a redirect test.1
The solution is to use in batch file:
echo This is just a redirect test. 1>CapturedStandardOutput.txt
This results in execution of the line:
echo This is just a redirect test. 1>CapturedStandardOutput.txt
And there is now the line below in file CapturedStandardOutput.txt:
This is just a redirect test.
What you can't see here in the browser window is that the line in the text file ends now with a trailing space in comparison to first example. Therefore best is to use >
and >>
always without 1 as otherwise it is not really simple to control what is written to the text file.
One more hint:
To redirect a text to a file which ends with 1, 2, ..., 9 it is necessary to escape the number with ^
.
Execution of a batch file with
echo Number is ^1>CapturedStandardOutput.txt
@pause
results in executing the command line
echo Number is 1 1>CapturedStandardOutput.txt
and in file CapturedStandardOutput.txt the line
Number is 1
with no trailing space at end of the line.
0 left to >
and >>
must not be escaped to get number 0 written into a text file.
这篇关于运行从Java批处理文件时,随机1 - 之前出现的GT;>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!