2013-10-27 46 views
1

這是一個批處理文件(在Windows 7中)。 我嘗試了一些組合和更改,但確切的輸出未實現。請檢查下面。循環出錯

setlocal enableDelayedExpansion 

    set c= 

    for %i in (1 2 3 4) do (
    set b=%c% %i,2013/ 
    call echo %b% 
    set c=%b% 
    ) 

我想輸出象下面這樣:

1,2013/ 

1,2013/2,2013/ 

1,2013/2,2013/3,2013/ 

1,2013/2,2013/3,2013/4,2013/ 

但它是未來像下面。

C:\用戶\ Ashutosh說PC> SETLOCAL enableDelayedExpansion

C:\用戶\ Ashutosh說PC>集合C =

C:\用戶\ Ashutosh說PC>爲%I(1 2 3 4 ?)DO( 更多設定b =%C%%I,2013/ 多個呼叫回波%b% 更多集合C =%b% 更多 更多)

C:???\ Users \用戶Ashutosh PC>( set b =%c%1,2013/ call echo%b% 組C =%B% ) %C%1,2013/

C:\用戶\ Ashutosh說PC>( 集B =%C%2,2013/ 呼叫回波%B% 集合C =%b% ) %C%2,2013/

C:\用戶\ Ashutosh說PC>( 集b =%C%3,2013/ 呼叫回波%b% 集合C =%b % ) %c%3,2013/

C:\ Users \ Ashutosh PC>( set b =%c %4,2013/ 呼叫回波%B% 集合C =%B% ) %C%4,2013/

C:\用戶\ Ashutosh說PC>

+4

這是什麼語言? –

+3

你真的得到了什麼輸出? –

+0

它是Windows @RobinGreen中的批處理文件 – KD333

回答

2
@echo off 
    setlocal enableDelayedExpansion 

    set "c=" 

    for %%i in (1 2 3 4) do (
    set b=!c! %%i,2013/ 
    call echo !b! 
    set c=!b! 
    ) 
    endlocal 

http://www.robvanderwoude.com/variableexpansion.php

+0

感謝npocmaka的回覆,但我在執行代碼時遇到了錯誤。 C:\用戶\ Ashutosh說PC>爲%% i的(1 2 3 4)做( %%我是意想不到此時 似乎CMD提示符不識別雙(%%)符號 – KD333

+1

。你的問題是「這是一個批處理文件」,npocmaka的答案在一個批處理文件中工作,如果你想從CMD提示符執行,你需要使用%i而不是%% i – RGuggisberg

+0

hey RGuggisberg和npocmaka ..非常感謝你的支持......現在通過批處理文件(而不是CMD)進行測試......它工作得很好。 – KD333