Jump to content

[BTACH] 'SET Va=St' with '& ECHO' doesn't work


Recommended Posts

HI,

I'm trying to get this first command line here to work but i have no luck to get it working. :(

@ECHO OFFSET "FN=FolderName" & ECHO "%FN%"PAUSE



But on separate lines i works. :crazy:

@ECHO OFFSET "FN=FolderName"ECHO "%FN%"PAUSE
Edited by Outbreaker
Link to comment
Share on other sites


Try:

@ECHO OFFSETLOCAL ENABLEEXTENSIONSSET "FN=FolderName" & ECHO "%FN%"PAUSESET FN=CALL SET "FN=FolderName" & FOR /F "Tokens=2 delims==" %%A IN ('SET FN') DO ECHO "%%A"PAUSESET FN=SETLOCAL ENABLEDELAYEDEXPANSIONSET "FN=FolderName" & ECHO "!FN!"PAUSE

;)

 

jaclaz

Link to comment
Share on other sites

The first example didn't work so i used the last one but since i need to have everything in one code line i used this code below this one should work but it doesn't. :(

CMD /Q /C V:ON SET "FM=FolderName" & ECHO "!FM!"
Edited by Outbreaker
Link to comment
Share on other sites

 

The first example didn't work so i used the last one but since i need to have everything in one code line i used this code below this one should work but it doesn't. :(

CMD /Q /C V:ON SET "FM=FolderName" & ECHO "!FM!"

Well, you are in the (common BTW) issue of mis-communicating, the known xyz or the chocolate covered banana:

http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/put-down-the-chocolate-covered-banana.html

 

You want to reach a goal, but you do not specify it and ask a question related to a tiny bit of what you believe to be the way to reach that goal (which may or may not the "right" way) 

 

However :) try:

CMD V:ON /Q /C "SET "FN=FolderName" &FOR /F "tokens=2 delims==" %%A IN ('SET FN') DO ECHO "%%A""

jaclaz

Link to comment
Share on other sites

Am I missing something?

CMD /Q/D/C "SET "FN=FolderName"&CALL ECHO;"%FN%""

If you want to actually read the output then use either:

CMD /Q/D/K "SET "FN=FolderName"&CALL ECHO;"%FN%""

or:

CMD /Q/D/C "SET "FN=FolderName"&CALL ECHO;"%FN%"&PING -n 4 127.0.0.1>NUL"
Link to comment
Share on other sites

 

Am I missing something?

 

 

 

Not yet. :w00t:

 

Till now the usual screenplay has been followed to the letter:

  1. someone asks something about batch
  2. jaclaz provides a possible solution
  3. Yzöwl provides another (often better) one :yes:

at this point normally Gunsmokingman enters the scene and posts a .vbs to the same effect of the batches/snippets posted earlier, this time since the topic seems to be "strictly" batch, this might not happen :unsure: that would be a twist to the story... ;)

 

jaclaz

Link to comment
Share on other sites

Strangely, I think I really am missing something!
 
...the point!

 

Why set a variable for a fraction of a second, the sole purpose of which is to output its value to a console which would have closed before reading it?

Link to comment
Share on other sites

You are not missing it :no:, it simply does not exist :w00t:, the whole point of the game, when played outside common rules, is to continuously shift the actual question towards something else at each iteration.

 

Technically ;) this is often referred to as "Ninja Point" :whistle::

motivator9839607.jpg

 

The original question made some sense, but as soon as a "normal" solution (actually two) were proposed, the question became different (having no actual practical use) and I suspect that even the modified question has very little in common with the actual goal/expected result/intended use, hence the reference to the xyz issue.

 

 

jaclaz

Link to comment
Share on other sites

 

The first example didn't work so i used the last one but since i need to have everything in one code line i used this code below this one should work but it doesn't. :(

CMD /Q /C V:ON SET "FM=FolderName" & ECHO "!FM!"

Something to learn from this example.

 

The command string should follow /C or /K. Not using /C or /K immediately before the command string can expect failure.

V:ON would be an invalid parameter as a leading forward slash would be expected. CMD seems to ignore V:ON and thus delayed expansion is not turned on.

The command string has more then 2 double quotes. CMD may strip outer double quotes which may leave the command string as invalid. I would add extra outer double quotes on the command string and use the /S parameter to force CMD to strip those outer double quotes to be safe.

 

This information can be viewed by using the command CMD /? .

 

Following the information I mentioned above, I would use

CMD /S /Q /V:ON /C "SET "FM=FolderName" & ECHO "!FM!""

which tests as working.

Edited by MHz
Link to comment
Share on other sites

Interesting this one works great thanks. :thumbup

For anyone who asks themselves why i need this command here is the complete command i use. ;)

CMD /S /Q /V:ON /C "SET "EmptyFolder=%ProgramFiles%\Software\temp" & PUSHD "!EmptyFolder!" && (RMDIR "!EmptyFolder!" /S /Q 2>NUL & POPD)"

This will delete everything in a folder but will not delete the Root folder (temp).  :)

I'm only not sure if i should use the /S at the beginning or not it works with both. :ph34r:

Edited by Outbreaker
Link to comment
Share on other sites

...

I'm only not sure if i should use the /S at the beginning or not it works with both. :ph34r:

Not needed in your case as the command string does not start with a double quote and end with a double quote. I saw all the double quotes and considered mentioning the /S yet after I posted I noticed that the command string begins with the command Set with double quotes coming later in the string.

 

If you do have a command string starting and ending with double quotes like (omitting the CMD /Q /C stuff being shown, rather just the command string)

"path\to\file.exe" > "path\to\logfile.log"

then CMD may strip the outer double quotes following legacy conditions. So it would be executed as

path\to\file.exe" > "path\to\logfile.log

which would fail as the redirection character is now double quoted with the white space.

 

Apologies for any confusion. You can still use the /S and use extra double quotes if you want though it is not needed with your command line shown.

Link to comment
Share on other sites

Interesting this one works great thanks. :thumbup

For anyone who asks themselves why i need this command here is the complete command i use. ;)

CMD /S /Q /V:ON /C "SET "EmptyFolder=%ProgramFiles%\Software\temp" & PUSHD "!EmptyFolder!" && (RMDIR "!EmptyFolder!" /S /Q 2>NUL & POPD)"

...but you're setting a variable for no reason

 

Without changing your code at all and just removing the pointless set you've shortned the command line!

CMD /S /Q /V:ON /C "PUSHD "%ProgramFiles%\Software\temp" && (RMDIR "%ProgramFiles%\Software\temp" /S /Q 2>NUL & POPD)"

...now you could even ignore the /s and /v switches and shorten it further.

Link to comment
Share on other sites

I am still failing to see the actual practical use of this command, I mean is it to be included in a batch file or - as it seems - it is intended to be typed on the command line? :unsure:

 

jaclaz

Link to comment
Share on other sites

I use this command in a .inf file. ;)

11,,cmd.exe,,,"/Q /V:ON /C ""SET ""EmptyFolder=%ProgramFiles%\Software\temp"" & PUSHD ""!EmptyFolder!"" && (RMDIR ""!EmptyFolder!"" /S /Q 2>NUL & POPD)"""
Edited by Outbreaker
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...