Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
108 views
in Technique[技术] by (71.8m points)

How do you use SETLOCAL in a batch file?

How do you use setlocal in a batch file? I am just learning scripting and would like it explained to me in very simple terms.

I have a script that stops and says < was unexpected at this time it may have something to do with not having any setlocal statements in the script.

question from:https://stackoverflow.com/questions/13704223/how-do-you-use-setlocal-in-a-batch-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You make the first line SETLOCAL. This example is from the linked article below:

rem *******Begin Comment**************
rem This program starts the superapp batch program on the network,
rem directs the output to a file, and displays the file
rem in Notepad.
rem *******End Comment**************
@echo off
setlocal
path=g:programssuperapp;%path%
call superapp>c:superapp.out
endlocal
start notepad c:superapp.out

The most frequent use of SETLOCAL is to turn on command extensions and allow delayed expansion of variables:

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

For more info on SETLOCAL see the Command Line Reference at Microsoft TechNet.

Direct link to Setlocal


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...