[英]how to pass parameters to batch file using java textbox
I am running a batch file, where I want to pass parameters from Textbox 我正在运行一个批处理文件,我想在其中传递文本框的参数
Batch: test.bat 批次:test.bat
@echo off
set par1=%1
echo Parameter 1 is %par1%
mkdir %par1%
Java: Java:
Process p = Runtime.getRuntime().exec("c:\\test.bat");
How to pass parameter to Test.bat
file? 如何将参数传递给
Test.bat
文件?
You can just add the parameter to the command line: 您只需将参数添加到命令行即可:
Process p = Runtime.getRuntime().exec("c:\\test.bat xyz");
This will pass xyz
to the batch file. 这会将
xyz
传递到批处理文件。
But Runtime.getRuntime().exec(..)
is not a good way to execute an external program. 但是
Runtime.getRuntime().exec(..)
不是执行外部程序的好方法。 You should use ProcessBuilder
instead. 您应该改为使用
ProcessBuilder
。
将它们传递给数组:
Runtime.getRuntime().exec(new String[] {"c:\\test.bat", "-p", "firstParam", "--secondparam"} )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.