2012-04-13 71 views
0

下面是此批IM makeing括號錯誤

@echo off 
title TXTanimation 
set dir101=C:\USers\Jake\Desktop\file.bat 
goto menu 
echo Lets make a text animation 
pause 
set /p dir101=where will the .bat be saved: 
echo @ECHO OFF > %dir101% 
:menu 
echo 0=Edit important information 
echo 1=Display .txt 
echo 2=Play sound 
echo 3=Close sound player 
echo 4=Add nessicary wait between .txt 
echo 5=Label point 
echo 6=Edit variable 
echo 7=Goto point 
echo 8=Create IF sentence 
echo 9=End it 
Set /p choose=which one: 

If '%choose%'=='0' ( 
SEt /p title=What is the title 
:LOL101 
set /p color=what color do you want (type test to experiment with the colors) 
If '%color%'=='test' goto tester 
goto model 
:tester 
SEt /p test=Please give hexadecimal number type exit to leave: 
if '%test%'=='exit' goto LOL101 
color %test% 
goto tester 
:model 
echo title %title% >> %dir101% 
echo color %color% >> %dir101% 
) 

If '%choose%'=='1' ( 
set /p dir=what is the dir of your .txt: 
) 
If '%choose%'=='1' ( 
echo cls >> %dir101% 
echo type %dir% >> %dir101% 
) 
If '%choose%'=='4' ( 
SEt /p thyme=How much milliseconds 250 is usual: 
echo ping 192.168.1.1 -n 1 -w %thyme% >> %dir101% 
) 
goto menu 
If '%choose%'=='9' ( 
echo Thanks for making 
pause 
) 

其將被用於在.bat文件中創建的.txt動畫。我可以完成它,但我首先需要解決一個問題。

的問題是,它 echo title %title% >> %dir101% echo color %color% >> %dir101% 即使有括號

+0

愚蠢的問題時,做單引號在.bat文件或cmd中工作?我只見過雙引號。 – Bill 2012-04-13 01:00:04

+0

@Bill當涉及到IF語句 – 2012-04-13 01:01:18

+0

@JakeInc時,它無關緊要。你是說你的代碼執行'echo title%title%>>%dir101%'和'echo color%color%>>%dir101%',即使你的選擇沒有值'0' ?正如dbenham所說,你的實際問題有點不清楚。 – iesou 2012-04-13 13:38:54

回答

1

你是不是對你有什麼問題非常清楚。但是,我發現代碼存在一個常見問題。

您正在設置環境變量,然後嘗試使用立即擴展訪問該值,所有這些都在由括號括起來的相同代碼塊中。這是行不通的,因爲擴展發生在塊被解析時,並且在執行任何操作之前,整個塊將被一次解析。所以你最終得到的值是在塊內設置值之前存在的。

解決方案是在腳本的頂部使用SETLOCAL EnableDelayedExpansion啓用延遲擴展。然後使用延遲擴展(!var!)而不是正常擴展(%var%)在執行時而不是在解析時獲取變量的值。

在命令提示符下的更多信息,請鍵入HELP SET並開始在該開始段落讀「最後,已添加了延遲環境變量擴展支持......」

+0

@iesou對不起,我不清楚我對這個有點新鮮 – 2012-04-13 16:46:17