apache1048
asked on
Using Set with output from a command?
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.
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.
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??
Is this what you are asking??
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
for %%i in ('echo exit^|cmd /q /k "ls -lrt W3SVC2 | tail -1 | gawk ^"{print $9}^" "') do NameOfBatchFile %%i
Walkabout
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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
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
> 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.
> 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.
Is this what you are asking??