2014-05-07 49 views
-2

我在將參數傳遞給.bat文件時遇到問題。我從java程序調用它並傳遞一些參數,但其中一個是我看不到的字符串,我不知道它的長度,它可能有空格,引號等。傳遞批處理參數

例如:test.bat 05 07 2014 this is "a test" cheers ,我需要捕捉它們是這樣的:

%1: 05 
%2: 07 
%3: 2014 
%4: this is "a test" cheers 

我無法找到一個方法來做到這一點! :(

喜歡的東西%4 to %last%*但在第四個參數開始..將是巨大的

我也試着給它喜歡:

test.bat 05 07 2014 "this is "a test" cheers" 

這使我:

%1: 05 
%2: 07 
%3: 2014 
%4: this is "a 
%5: test" cheers 

非常感謝!

+0

而不是雙引號嘗試單引號,也'''可能無法正常工作,因爲它是一個通配符。 – Vishrant

+0

你試過'test.bat 05 07 2014這是「測試」嗎? – tmlai

回答

0

一種方法:

@echo off 
setlocal enabledelayedexpansion 

set $Last=%* 
set $Last=!$Last:%1=! 
set $Last=!$Last:%2=! 
set $Last=!$Last:%3=! 
echo %1 
echo %2 
echo %3 
echo !$last:~3!