Using Set with output from a command?

apache1048
apache1048 used Ask the Experts™
on
I have a batch file which I need to dynamically set a parameter in. The parameter is from a command or a file.

The output is produced from the follwing line

ls -lrt W3SVC2 | tail -1 | gawk "{print $9}" and the output is someting like ex021219.log - I need to make this a variable within a batch file. Can this be done using set? Or has anyone any ideas of another method? I have output it to a file and tried to < it to the set but that does npot work. Any clues?

The command is from UNIX utilities for windows and works fine for what I want The issue is just getting the output to become a variable.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If I enter SET WTEST=test AND then run SET I can see the variable WTEST with the value of test.  The problem is that the variable does not survive the closing of the command prompt that enters it.  It only lives in that session.

Is this what you are asking??

If I enter SET WTEST=test AND then run SET I can see the variable WTEST with the value of test.  The problem is that the variable does not survive the closing of the command prompt that enters it.  It only lives in that session.

Is this what you are asking??

OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Darrell PorterEnterprise Business Process Architect

Commented:
Have you tried the following?

for %%i in ('echo exit^|cmd /q /k "ls -lrt W3SVC2 | tail -1 | gawk ^"{print $9}^" "') do NameOfBatchFile %%i

Walkabout

Commented:
Hi apache1048,
did any of the above comments helped you? If yes can you please choose it as an answer, if not is it possible for you to post an update so that this question can be finalised. Thanx in advance

Pasha

Cleanup Volunteer

Author

Commented:
None of the answers submitted actually answered the question. I solved the issue by working it a different way. Thanks to the people who tried though, I guess the question was confusing.

Commented:
apache1048,
Can you please post the solution in here so that other users having the same problem can use your information to resolve their problems. Thanks

Commented:
> echo bob > name.txt
> for /f %i in (name.txt) do @echo name=%i
name=bob

here's what i do when assigning current working directory to a variable within a batch script

for /f %%i in ('pwd') do CWD=%%i

note: variable "i" is double escaped (ie "%%") within a batch script, but only single escaped on command line

for more see 'for /?'

sorry i'm a year late with this answer, but i was searching for the answer to this question myself, found  this question with no answer, continued researching, found the answer, and then decided to archive the answer here for all those that come behind me.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial