Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

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

- - - - -

  • Please log in to reply
21 replies to this topic

#1
Outbreaker

Outbreaker

    Advanced Member

  • Member
  • PipPipPip
  • 323 posts
  • Joined 08-August 07
  • OS:Windows 7 x86
  • Country: Country Flag

HI,

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

@ECHO OFF
SET "FN=FolderName" & ECHO "%FN%"
PAUSE



But on separate lines i works. :crazy:

@ECHO OFF
SET "FN=FolderName"
ECHO "%FN%"
PAUSE

Edited by Outbreaker, 12 March 2015 - 07:29 AM.



How to remove advertisement from MSFN

#2
jaclaz

jaclaz

    The Finder

  • Developer
  • 15,180 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

Try:

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET "FN=FolderName" & ECHO "%FN%"
PAUSE

SET FN=
CALL SET "FN=FolderName" & FOR /F "Tokens=2 delims==" %%A IN ('SET FN') DO ECHO "%%A"
PAUSE

SET FN=
SETLOCAL ENABLEDELAYEDEXPANSION
SET "FN=FolderName" & ECHO "!FN!"
PAUSE

;)

 

jaclaz



#3
Outbreaker

Outbreaker

    Advanced Member

  • Member
  • PipPipPip
  • 323 posts
  • Joined 08-August 07
  • OS:Windows 7 x86
  • Country: Country Flag

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, 12 March 2015 - 08:48 AM.


#4
jaclaz

jaclaz

    The Finder

  • Developer
  • 15,180 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

 

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.ntlw...red-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


  • Outbreaker likes this

#5
Outbreaker

Outbreaker

    Advanced Member

  • Member
  • PipPipPip
  • 323 posts
  • Joined 08-August 07
  • OS:Windows 7 x86
  • Country: Country Flag

Thank you this command line is working great. :w00t:



#6
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,053 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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"


#7
jaclaz

jaclaz

    The Finder

  • Developer
  • 15,180 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

 

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


  • Outbreaker likes this

#8
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,053 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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?



#9
jaclaz

jaclaz

    The Finder

  • Developer
  • 15,180 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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::

Spoiler

 

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



#10
MHz

MHz

    Just simple

  • Member
  • PipPipPipPipPipPipPip
  • 1,666 posts
  • Joined 02-August 04
  • OS:Windows 7 x64
  • Country: Country Flag

 

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, 13 March 2015 - 09:20 PM.

  • Outbreaker likes this

#11
Outbreaker

Outbreaker

    Advanced Member

  • Member
  • PipPipPip
  • 323 posts
  • Joined 08-August 07
  • OS:Windows 7 x86
  • Country: Country Flag

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, 13 March 2015 - 10:50 PM.


#12
MHz

MHz

    Just simple

  • Member
  • PipPipPipPipPipPipPip
  • 1,666 posts
  • Joined 02-August 04
  • OS:Windows 7 x64
  • Country: Country Flag
...

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.


  • Outbreaker likes this

#13
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,053 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.



#14
jaclaz

jaclaz

    The Finder

  • Developer
  • 15,180 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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



#15
Outbreaker

Outbreaker

    Advanced Member

  • Member
  • PipPipPip
  • 323 posts
  • Joined 08-August 07
  • OS:Windows 7 x86
  • Country: Country Flag

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, 14 March 2015 - 06:52 AM.


#16
jaclaz

jaclaz

    The Finder

  • Developer
  • 15,180 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

So - as expected  - you don't really need to set the variable at all and additionally you have no particular limitation in the complexity or length of the command string.

 

jaclaz



#17
Outbreaker

Outbreaker

    Advanced Member

  • Member
  • PipPipPip
  • 323 posts
  • Joined 08-August 07
  • OS:Windows 7 x86
  • Country: Country Flag

I'm using this command multiple times and it makes it easier to edit and to find typos and i will also using this code in a different scenario. ;)


Edited by Outbreaker, 14 March 2015 - 08:11 AM.


#18
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,053 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Surely that's what the [Strings] section is designed to do!

[Strings]
EmptyFolder = "PathTo\MyDir"

Then you may be able to just do this!

PUSHD %EmptyFolder%&&RD/S/Q %EmptyFolder%


#19
jaclaz

jaclaz

    The Finder

  • Developer
  • 15,180 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

Then you may be able to just do this!

.. and thus here goes yet another demonstration of the futility of falling in the xyz issue, if Outbreaker had since the beginning explained what his ACTUAL GOAL was and provided the needed context information, not only he would have had a valid solution faster, but it would have been better and simpler. :thumbup

 

jaclaz



#20
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,915 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag

Well, you are in the (common BTW) issue of mis-communicating, the known xyz or the chocolate covered banana:
http://homepage.ntlw...red-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)

...

Am I missing something?

...

Not yet.
 
Till now the usual screenplay has been followed to the letter:

  • someone asks something about batch
  • jaclaz provides a possible solution
  • 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,

...

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

...

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.
 
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.

...

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

...

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?

...

So - as expected - you don't really need to set the variable at all and additionally you have no particular limitation in the complexity or length of the command string.

...

Then you may be able to just do this!

...

.. and thus here goes yet another demonstration of the futility of falling in the xyz issue, if Outbreaker had since the beginning explained what his ACTUAL GOAL was and provided the needed context information, not only he would have had a valid solution faster, but it would have been better and simpler.

 


LOL GSM and I have had similar "adventures" with Outbreaker, with similar results. Unfortunately, this thread was indeed as expected. :)

Cheers and Regards


Posted Image


#21
Redhatcc

Redhatcc

    Advanced Member

  • Patrons
  • 335 posts
  • Joined 27-February 08
  • OS:none specified
  • Country: Country Flag

Throwing this in the mix. Put the echo first then set.

@echo off 
echo|set /p"FN=FolderName"
Pause

Citrix Engineer - AFCENT


#22
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,053 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Throwing this in the mix. Put the echo first then set.

@echo off 
echo|set /p"FN=FolderName"
Pause

 

…unfortunately however, the actual task did not involve outputting anything at all to the screen!

 

Oh and also Outbreaker, since you are invoking the commands from an inf, there should also be no reason why you need to join all of the commands into a single line.

11,,cmd.exe,,,"/Q/C ""FOR /F ""DELIMS="" %A IN ('DIR/B/AD ""%ProgramFiles%\Software\temp\""') DO RD/S/Q ""%A"""
11,,cmd.exe,,,"/Q/C ""DEL/F/Q/A ""%ProgramFiles%\Software\temp\*.*"""





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users