Page 1 of 1

Is this possible? about Variable resolved to its value

Posted: 08 Jul 2011 22:27
by Huidong
I encountered something strange with defraggler's command-line tool df.exe

This works:

Code: Select all

open '"D:\Portable\Defraggler\df.exe" <selitems> /S';
This works, too:

Code: Select all

open '"D:\Portable\Defraggler\df.exe" "C:\file1.avi" /S';
But this doesn't work:

Code: Select all

//why?
  $ToDefrag = quote("C:\file1.avi");
  open '"D:\Portable\Defraggler\df.exe" $ToDefrag /S';
Although df handles <selitems> w/o problem, it seems that it does not like the symbol "$"?

That's my guess.. I don't quite understand, I thought $ToDefrag is resolved to "C:\file1.avi" before being fed to df.exe, so why df doesn't like it? I don't know the internals, could some one help?
Thanks!

Re: Is this possible? about Variable resolved to its value

Posted: 08 Jul 2011 22:42
by Stefan
Help file > Advanced Topics > Scripting

Using Quotes in Scripting
(4) Variables are resolved in double-quotes and outside of any quotes, but not in single-quotes.


Try:

Code: Select all

$ToDefrag = "Huidong";
   msg '"D:\Portable\Defraggler\df.exe" $ToDefrag /S';
   msg "D:\Portable\Defraggler\df.exe $ToDefrag /S";
I don't know which quoting you should use for your command line,(i have always to try it out myself)
maybe follow my sig and read third post about quoting, and there "More examples collected from the forum:", perhaps that enlighten a bit.

Maybe:

Code: Select all

$ToDefrag = quote("C:\file1.avi");
  open "D:\Portable\Defraggler\df.exe $ToDefrag /S";
or:

Code: Select all

$ToDefrag = quote("C:\file1.avi");
  open """D:\Portable\Defraggler\df.exe"" $ToDefrag /S";
Tell us which works.

Re: Is this possible? about Variable resolved to its value

Posted: 08 Jul 2011 23:19
by Huidong
Thank you, Stefan!
You're right, variables in single quotes are not resolved, but here I noticed something weird
This does not work, as expected:

Code: Select all

open 'D:\Portable\Defraggler\df.exe <selitems> /S'
This does NOT work, not expected:

Code: Select all

open "D:\Portable\Defraggler\df.exe <selitems> /S"
Even though, in step mode, <selitems> IS resolved!

However, this works, totally not expected (but I've been using this for months w/o realizing its strangeness):

Code: Select all

open '"D:\Portable\Defraggler\df.exe" <selitems> /S'
And you know what, from step mode, <selitems> is NOT resolved!!

Why, why?

Edit:
As you wrote, this works as expected, and <selitems> is resolved

Code: Select all

open """D:\Portable\Defraggler\df.exe"" <selitems> /S"
but the case where single quotes are used, why it works at all?

Re: Is this possible? about Variable resolved to its value

Posted: 08 Jul 2011 23:43
by Huidong
Stefan wrote: Maybe:

Code: Select all

$ToDefrag = quote("C:\file1.avi");
  open "D:\Portable\Defraggler\df.exe $ToDefrag /S";
or:

Code: Select all

$ToDefrag = quote("C:\file1.avi");
  open """D:\Portable\Defraggler\df.exe"" $ToDefrag /S";
Tell us which works.
Alright, things becomes a little clearer! Thanks! Your second code works, so
1) Even though df's path has no space, its path MUST be quoted. (WHY?? But maybe that's just the rule)
2) $ToDefrag had better be quoted in general, but if it has no space, quote is not necessary.
(see the offical reference http://www.piriform.com/docs/defraggler ... parameters)

So the remaining confusion is:
In my last post, in single quotes, <selitems> apparently is NOT resolved, according to the documentation Stefan mentioned, as well as indicated during the stepping. However, during the open of df.exe, <selitems> is SOMEHOW eventually resolved... WHY??