-
java调用bat传参_bat调用jar包并传入多个参数
2021-02-12 23:01:12在Main函数接收bat文件传递的参数(String[] args)如: String ip =args[0];String user=args[1];String password=args[2];2.将项目打包@安装插件fatjar解压插件将"net.sf.fjep.fatjar_0.0.31.zip"放在eclipse\...下面的主程序是通过eclipse写的:
1.在Main函数接收bat文件传递的参数(String[] args)
如: String ip =args[0];
String user=args[1];
String password=args[2];
2.将项目打包
@安装插件fatjar
解压插件将"net.sf.fjep.fatjar_0.0.31.zip"放在eclipse\plugins目录下
@重启Eclipse在右击项目'"Bulid Fat Jar"
【Jar-Name】输入生成的jar名;【Main_Class】选择主类;
3.在导出的jar包同级目录下生成对应的bat文件
================================================================================================
@echo off
:start
cls
echo ================数据库选择====================
echo 请务必认真核对- -
echo 1.数据库连接:jdbc:oracle:thin:@10.133.10.120:1521:orcl
echo 2.手工输入数据库
echo 3.退出
echo ==============================================
set /p choice= 请选择:
if %choice%==1 goto 1
if %choice%==2 goto 2
if %choice%==3 exit
:1
set ip=10.133.10.120:1521:orcl
set user=sjpt_gd
set pass=sjpt_gd
cd F:\bat
java -jar -Xms512m -Xms1024m batProject_fat.jar %ip% %user% %pass%
echo ==================接口取数结束================
echo =======若要再次执行请按两次Enter即可==========
pause
goto :start
:2
cls
echo ================参数值设置====================
echo 服务器地址格式:10.133.10.120:1521:orcl
echo 数据库连接:jdbc:oracle:thin:@10.133.10.120:1521:orcl
echo ==============================================
set /p ip=请输入服务器地址:
echo %ip%
set /p user=数据库用户名:
echo %user%
set /p pass=数据库用户密码:
echo %pass%
cd F:\bat
java -jar -Xms512m -Xms1024m batProject_fat.jar %ip% %user% %pass%
echo ==================接口取数结束================
pause
goto :start
================================================================================================
这样子后就可以用bat文件调用
-
java调用bat传参_获取Windows批处理脚本(.bat)中传递的参数列表
2021-03-03 12:12:08因此,可以说运行:“ arg.bat --x hello-world”,然后可以使用语句“ IF DEFINED –x echo%-x%”,结果将为“ hello-world”。 如果运行批处理,应该更有意义。 @setlocal enableextensions ...我想找到Windows批处理副本,它与Bash的$@对应,其中包含传递给脚本的所有参数的列表。
还是我不得不去shift ?
#1楼
检索脚本中所有参数的方法如下:
@ECHO off
ECHO The %~nx0 script args are...
for %%I IN (%*) DO ECHO %%I
pause
#2楼
这是获取args并将其设置为env vars的一种相当简单的方法。 在此示例中,我仅将它们称为键和值。
将以下代码示例另存为“ args.bat”。 然后从命令行调用您保存的批处理文件。 例如:arg.bat --x 90 --y 120
我提供了一些echo命令来逐步引导您完成此过程。 但是最终结果是--x的值为90,而--y的值为120(也就是说,如果您按照上面指定的示例运行;-))。
然后,您可以使用“如果已定义”条件语句来确定是否运行代码块。 因此,可以说运行:“ arg.bat --x hello-world”,然后可以使用语句“ IF DEFINED –x echo%-x%”,结果将为“ hello-world”。 如果运行批处理,应该更有意义。
@setlocal enableextensions enabledelayedexpansion
@ECHO off
ECHO.
ECHO :::::::::::::::::::::::::: arg.bat example :::::::::::::::::::::::::::::::
ECHO :: By: User2631477, 2013-07-29 ::
ECHO :: Version: 1.0 ::
ECHO :: Purpose: Checks the args passed to the batch. ::
ECHO :: ::
ECHO :: Start by gathering all the args with the %%* in a for loop. ::
ECHO :: ::
ECHO :: Now we use a 'for' loop to search for our keys which are identified ::
ECHO :: by the text '--'. The function then sets the --arg ^= to the next ::
ECHO :: arg. "CALL:Function_GetValue" ^ ^ ::
ECHO :: ::
ECHO ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO.
ECHO ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO :: From the command line you could pass... arg.bat --x 90 --y 220 ::
ECHO ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO.
ECHO.Checking Args:"%*"
FOR %%a IN (%*) do (
CALL:Function_GetValue "--","%%a"
)
ECHO.
ECHO ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO :: Now lets check which args were set to variables... ::
ECHO ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO.
ECHO ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO :: For this we are using the CALL:Function_Show_Defined "--x,--y,--z" ::
ECHO ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO.
CALL:Function_Show_Defined "--x,--y,--z"
endlocal
goto done
:Function_GetValue
REM First we use find string to locate and search for the text.
echo.%~2 | findstr /C:"%~1" 1>nul
REM Next we check the errorlevel return to see if it contains a key or a value
REM and set the appropriate action.
if not errorlevel 1 (
SET KEY=%~2
) ELSE (
SET VALUE=%~2
)
IF DEFINED VALUE (
SET %KEY%=%~2
ECHO.
ECHO ::::::::::::::::::::::::: %~0 ::::::::::::::::::::::::::::::
ECHO :: The KEY:'%KEY%' is now set to the VALUE:'%VALUE%' ::
ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO.
ECHO %KEY%=%~2
ECHO.
REM It's important to clear the definitions for the key and value in order to
REM search for the next key value set.
SET KEY=
SET VALUE=
)
GOTO:EOF
:Function_Show_Defined
ECHO.
ECHO ::::::::::::::::::: %~0 ::::::::::::::::::::::::::::::::
ECHO :: Checks which args were defined i.e. %~2
ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO.
SET ARGS=%~1
for %%s in (%ARGS%) DO (
ECHO.
ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO :: For the ARG: '%%s'
IF DEFINED %%s (
ECHO :: Defined as: '%%s=!%%s!'
) else (
ECHO :: Not Defined '%%s' and thus has no value.
)
ECHO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ECHO.
)
goto:EOF
:done
#3楼
@echo off
:start
:: Insert your code here
echo.%%1 is now:%~1
:: End insert your code here
if "%~2" NEQ "" (
shift
goto :start
)
#4楼
Windows版本(虽然需要socat)
C:\Program Files (x86)\Git\bin>type gitproxy.cmd
socat STDIO PROXY:proxy.mycompany.de:%1:%2,proxyport=3128
设置:
C:\Users\exhau\AppData\Roaming\npm>git config --global core.gitproxy gitproxy.cmd
#5楼
以下代码模拟一个数组(' params ')-接受脚本接收的参数,并将它们存储在变量params_1 .. params_n ,其中n = params_0 =数组的元素数:
@echo off
rem Storing the program parameters into the array 'params':
rem Delayed expansion is left disabled in order not to interpret "!" in program parameters' values;
rem however, if a parameter is not quoted, special characters in it (like "^", "&", "|") get interpreted at program launch
set /a count=0
:repeat
set /a count+=1
set "params_%count%=%~1"
shift
if defined params_%count% (
goto :repeat
) else (
set /a count-=1
)
set /a params_0=count
rem Printing the program parameters stored in the array 'params':
rem After the variables params_1 .. params_n are set with the program parameters' values, delayed expansion can
rem be enabled and "!" are not interpreted in the variables params_1 .. params_n values
setlocal enabledelayedexpansion
for /l %%i in (1,1,!params_0!) do (
echo params_%%i: "!params_%%i!"
)
endlocal
pause
goto :eof
-
关于bat传参以及参数替换的研究
2013-11-14 13:18:06和linux的sh一样,bat里面也带有相应的参数变量 即 %1,%2,%3分别代表第一个,第二个,第三个参数,其中%0是代表当前脚本的名字,看代码。 d:\vv\test.bat @echo off echo this is %%0 %0 echo this...和linux的sh一样,bat里面也带有相应的参数变量 即 %1,%2,%3分别代表第一个,第二个,第三个参数,其中%0是代表当前脚本的名字,看代码。
d:\vv\test.bat
@echo off echo this is %%0 %0 echo this is %%1 %1 echo this is %%2 %2
另外还有一些扩充命令:
%~dp0 “d”为Drive的缩写,即为驱动器,磁盘、“p”为Path缩写,即为路径,目录
选项语法:
~0 - 删除任何引号("),扩充 %0
%~f0 - 将 %0 扩充到一个完全合格的路径名(“f”是file,即文件)
%~d0 - 仅将 %0 扩充到一个驱动器号
%~p0 - 仅将 %0 扩充到一个路径
%~n0 - 仅将 %0 扩充到一个文件名(“n”是name 文件名)
%~x0 - 仅将 %0 扩充到一个文件扩展名
%~s0 - 扩充的路径只含有短名(“s”为Short,短的)
%~a0 - 将 %0 扩充到文件的文件属性(“a”为attribute,即属性)
%~t0 - 将 %0 扩充到文件的日期/时间(“t”time)
%~z0 - 将 %0 扩充到文件的大小(Size 大小)
%~$PATH:0 - 查找列在路径环境变量的目录,并将 %0 扩充到找到的第一个完全合格的名称。
如果环境变量名未被定义,或者没有找到文件,此组合键会扩充到空字符串
可以组合修饰符来得到多重结果:
%~dp0 - 仅将 %0 扩充到一个驱动器号和路径
%~nx0 - 仅将 %0 扩充到一个文件名和扩展名
%~fs0 - 仅将 %0 扩充到一个带有短名的完整路径名
%~dp$PATH:0 - 查找列在路径环境变量的目录,并将 %I 扩充到找到的第一个驱动器号和路径。
%~ftza0 - 将 %0 扩充到类似输出线路的 DIR看代码:
@echo off echo this is %%0 %0 echo this is %%1 %1 echo this is %%2 %2 echo this is %%cd%% %cd% echo this is %%~dp0 %~dp0 echo this is %%~nx0 %~nx0 echo this is %%~fs0 %~fs0 echo this is %%~ftza0 %~ftza0 echo this is %~0 ~0 echo this is %%~f0 %~f0 echo this is %%~d0 %~d0 echo this is %%~p0 %~p0 echo this is %%~n0 %~n0 echo this is %%~x0 %~x0 echo this is %%~s0 %~s0 echo this is %%~a0 %~a0 echo this is %%~t0 %~t0 echo this is %%~z0 %~z0 echo this is %%~$PATH:0 %~$PATH:0 set tempt=%0 echo %tempt%
-
封装:一个bat调用另一个bat并传参
2021-03-29 11:26:13b.bat rem b.bat @echo on rem -----------变量定义区------------- set dbtag=%1% set basedir=E:\a\%2% echo %dbtag% echo %targetdir% a.bat start b.bat 111 2222 start b.bat 333 4444 rem call b.bat ...b.bat
rem b.bat @echo on rem -----------变量定义区------------- set dbtag=%1% set basedir=E:\a\%2% echo %dbtag% echo %targetdir%
a.bat
start b.bat 111 2222 start b.bat 333 4444 rem call b.bat 111 2222 rem call b.bat 333 4444
用call好像第二行就不会执行
-
bat(传参情况下)取得当前bat所在的目录路径
2016-05-03 20:34:00在传参情况下,取得bat文件所在的目录路径,可以使用: %~dp0 说明: 01.所谓传参情况是指,将某个文件拖放到bat文件上并放开。此种情况下执行的bat命令就是有带参数的。 02.上面末尾的0是指第0个参数,其实... -
python3 调用 .bat 及传参 os.system().txt
2020-05-07 10:12:45python调用外部命令及传参。 xx.bat,全景照片批处理命令,绝对路径,路径分隔符:"\" -> "/"。 参数1,2,可以是绝对、相对路径,比如: F:/LongGeTasks/streetView/streetImg3/ladybug_panora... -
python调用bat脚本传参_将参数从批处理文件传递给Python
2020-12-06 11:58:53I may not be able to see the console log in IDE while executing My batch file (.bat) start python test.py sample.xml My python file (test.py) def main(argv): sample = argv[1] #How to get argument ... -
CMD Bat 之间调用传参
2012-07-26 17:59:16a.bat文件内容: set input=%1% echo 这里是a.bat 运行代码:调用a.bat时,传了参数:%input% pause b.bat文件内容: %~dp0\a.bat 调用a.bat传入的参数143124124 pause 输出: D:\>D:\\a.... -
bat 脚本通过传参控制多个wifi模拟多用户连接
2021-03-02 10:11:03bat 脚本通过传参控制多个wifi模拟多用户连接: 使用方式打开命令行:test.bat on TZA all 或者 test.bat off TZA all @echo off set input1=%1% set input2=%2% set input3=%3% if %input1%==on ( echo turn on... -
NET BAT 执行控制台EXE 传参
2017-07-14 15:39:53bat 代码 start "" /d "C:\Users\SmllK\Desktop" "a.exe" 1 2 控制台代码 static void Main(string[] args) { Console.WriteLine(args[0]); Console.WriteLine(args[1]); -
[教程心得] Flash AIR 调用exe/bat且可以传参
2014-01-15 15:53:00Flash AIR 如何调用exe/bat?并且有些情况下需要传参,如何传参呢?看下面例子:cmd传参打开系统软键盘(参考http://bbs.9ria.com/thread-181265-1-1.html): import flash.desktop.NativeProcess; import ... -
bat批处理,指定文件夹,通过函数传参
2019-01-17 15:40:27bat批处理,指定文件夹,通过函数传参 -
bat文件中调用传参的问题
2018-09-17 18:02:00https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/ Conclusion In general, we can safely pass arbitrary command line argume... -
vbs如何传参给bat文件
2019-07-23 17:15:27在vbs中 例子 ... ws.run "C:\Users\Administrator\Desktop\rar.bat 我",0 在rar.bat中接受 %1代表的是参数的第一个位置,从左到右 依次 %2 ....... 也可以赋值 set s=%1 ... -
Java调用bat批处理文件动态传参问题
2016-09-21 09:01:341、使用JAVA调用bat文件的API //env这个Map的key和bat文件中的%key%的值要一样,这样才能替换bat里面的key的值! ProcessBuilder pBuilder = new ProcessBuilder(comm); if (env != null) { Map penv = pBuilder... -
java调用批文件(.bat)并动态传参
2018-11-02 16:08:55java代码: package test; import java.io.IOException;...比如说:bat的位置在C:/Users/Lenovo/Desktop/DCPScheduler/startTask.bat,但bat运行的位置是D:\sunline\installWares\eclipse\workspace\Test -
Bat执行Python脚本输出显示与传参的问题
2017-08-06 19:20:05bat调用python脚本时传参还得用start命令: @echo off start python showjar.py %* exit *%*表示将bat收到的所有参数,这样就无惧python带参数执行的问题了。 调用时新窗口会闪现一下,如果要不闪现就用pythonw... -
doc、bat、cmd、Python调用nodejs并传参
2021-03-01 08:58:58学了doc、nodejs、Python 现在需要在各个语言之间相互调用,排列组合一下一共有12种相互个组合。 doc文件会集成在文件bat,以下统称bat bat调用Python bat调用nodejs -
java操作批处理bat
2018-03-12 14:53:13java调用bat可执行批处理文件:Process process = Runtime.getRuntime().exec(ProxyRestartServerServlet.class.get...java不能向bat传参,可以通过动态生成bat文件来解决这个问题,直接将参数写入生成的bat中pri...