Re: Need Help With Script

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"Pegasus (MVP)" <I.can@xxxxxxxxxx> wrote in message
news:ufm5Q7BHJHA.740@xxxxxxxxxxxxxxxxxxxxxxx

"Will" <westes-usc@xxxxxxxxxxxxxx> wrote in message
news:zeidnW4I44EhB0vVnZ2dnUVZ_oWdnZ2d@xxxxxxxxxxxxxxx
I need help with a simple script. I want to put the output of a command
into an environment variable, and I tried this construction in a CMD
file:

for /f "usebackq delims=" %%i in (`D:\USR\BINTU\MKSNT\date +%a`) do set
dayofweek=%%i

The moment this line of the script executes, the script is terminated
with
no error. It looks to me like the date.exe command I am calling is
exiting
in a way that doesn't allow a return back to the script that called it.
The %dayofweek% environment variable is NOT being set.

Any thoughts on how I can get this to work?

--
Will


Did you try this somewhat simplified syntax?
@echo off
for /f "delims=" %%i in ('D:\USR\BINTU\MKSNT\date +%a') do set
dayofweek=%%i

A few questions:
- What's %a? If it's a loop variable (perhaps from an outer loop)
then it should be %%a.
- What's the + in front of %a? A switch marker?
- When you execute the command
D:\USR\BINTU\MKSNT\date > c:\test.txt
and examine c:\test.txt with a binary viewer (e.g. debug.exe), what
exactly do you see? Is it an ASCII file? Unicode? What are the last
few characters in the file?

The date.exe I am executing here is a Windows version of the Unix Date
command. The command:

date +%a

will give the three letter code for the day of the week. On Sunday it
would give output:

Sun

So to answer your question "%a" is NOT a loop variable from elsewhere in the
script. It is a literal text input string that is interpreted by the date
command for purposes of selecting an output.

Redirection of this command from the command line to a file put the
appropriate output there without any problems. Inspecting this output file
with debug gave the expected result of three ASCII characters followed by
0xD 0xA.

I tried your simplified syntax without usebackq or backquotes and the script
still dies in the same place.

--
Will


.



Relevant Pages