Quotes and spaces within the AT command

  • Thread starter Thread starter Csaba Gabor
  • Start date Start date
C

Csaba Gabor

I have a complex AT command I'd like to put on one line to avoid having
to use a batch file.

For comparison, I have successfully scheduled the following:
AT 22:38 "c:\Program Files\Mozilla Firefox\Firefox.exe"
http://bugzilla.mozilla.org/attachment.cgi?id=212413

But it turns out that before I invoke Firefox in this fashion I should
temporarily set an environment variable:
SET MOZ_NO_REMOTE=1

Therefore, I believe I want something like (in the final version the
/INTERACTIVE will be gone and the /K will become a /C):
AT 00:58 /INTERACTIVE %comspec% "/K SET MOZ_NO_REMOTE=1 && ""c:\Program
Files\Mozilla Firefox\Firefox.exe"" -p system
http://bugzilla.mozilla.org/attachment.cgi?id=212413"


Unfortunately, when I type AT to see what I got, it is something like:
1 Today 12:58 AM
C:\WINDOWS\system32\cmd.exe "/K SET MOZ_NO_REMOTE=1 && "c:\Program"
Files\Mozilla Firefox\Firefox.exe -p system
http://bugzilla.mozilla.org/attachment.cgi?id=212413


So the whole process falls over because of that space in Program Files.
I've tried varying the number of quotes and using ^ but I just haven't
figured out the AT quoting mechanism. It would be great if someone
could shore up my approach.

Thanks for any tips,
Csaba Gabor from Vienna


Explanation of where this is coming from: I want to schedule Firefox
(FF) hidden. I can do this if I schedule it via AT without the
/INTERACTIVE switch, and in that case it runs as a separate (hidden)
process with a User Name of SYSTEM. However, this only works per the
top AT command if there are no instances of FF when the scheduled task
runs. If there is already an FF instance, the scheduled task will
hang.

The trick is to get FF to start up in a separate process without
hanging, and that means with a distinct user profile (prefs.js file).
That MOZ_NO_REMOTE environment variable needs to be set so that FF will
utilize another profile (they (Mozilla) have a really bad way of doing
this - they create a temporary physical file in the profile directory
called parent.lock, so you must have that other profile in a separate
directory). If the environment variable is not set and FF does start
up a separate process, FF will hang.

Therefore, I figured to invoke %comspec%, have it set the environment
variable (which would thus be temporary), and then have it invoke FF on
a distinct profile (which I called 'system' and set up via the
instructions at
http://the-edmeister.home.comcast.net/advice-html/simul-profiles_batch-file.html).
Unfortunately, I can't figure out how to preserve those quotes within
the %comspec% argument. The explanation for what that first AT command
is doing is at: https://bugzilla.mozilla.org/show_bug.cgi?id=327849
 
Unfortunately, when I type AT to see what I got, it is something like:
1 Today 12:58 AM
C:\WINDOWS\system32\cmd.exe "/K SET MOZ_NO_REMOTE=1 && "c:\Program"
Files\Mozilla Firefox\Firefox.exe -p system
http://bugzilla.mozilla.org/attachment.cgi?id=212413


So the whole process falls over because of that space in Program Files.
I've tried varying the number of quotes and using ^ but I just haven't
figured out the AT quoting mechanism. It would be great if someone
could shore up my approach.

There are some other approaches, without having to worry about quoting
with the AT command.

The first option is to create a batch file to run the commands and
then schedule the batch file.

Another option is to find out the "short path" to Firefox.exe and use
that as quotes aren't needed.

for /f %%a in ("c:\Program Files\Mozilla Firefox\Firefox.exe") do (
set FFsPath=%%~sa)

Then call AT with %FFsPath% instead of the full path to FireFox.

A third option is to add the FireFox directory to your %path%, which
can be done in System Properties, Advanced then Environment variables.
Then you should only need to call Firefox.exe instead of the full
path.

Fourth, if this is for XP or 2003, try Schtasks. Since you don't want
an interactive task then this utility is more powerful than AT.

A couple of other options come to mind, but scheduling a batch file is
probably the simplest way to go.

Cheers,
Clay Calvert
(e-mail address removed)
Replace "Z" with "L"
 
Clay, I appreciate your ideas - they were helpful. Now I've run into
an additional problem (unrelated to the original one) which I'm not
sure how to handle, detailed below.

Clay said:
....

The first option is to create a batch file to run the commands and
then schedule the batch file.

An impressive list of ideas. I'd rather not use a batch file here
because it would be cluttering up the drive and making drive
writeability assumptions. Unless there is a compelling reason (as in
there is no other way), I don't want to increase my file count. I hate
extra files.
From your response, I take it that nobody has actually managed to
preserve quotes within the AT command (I just don't understand how it
could have been released without the developer putting it in).
Another option is to find out the "short path" to Firefox.exe and use
that as quotes aren't needed.

for /f %%a in ("c:\Program Files\Mozilla Firefox\Firefox.exe") do (
set FFsPath=%%~sa)

Then call AT with %FFsPath% instead of the full path to FireFox.

I settled on this idea, and it does the trick (but keep reading for the
follow on problem). To find the short names, I did (on my Win XP Pro
system):
dir /x

It turns out that Firefox requires one additional environment variable,
USERPROFILE. No problem, thinks I, and revamp the AT command thusly:
AT 12:09 /INTERACTIVE %comspec% "/K SET
USERPROFILE=C:\Docume~1\PeterG~1 & SET MOZ_NO_REMOTE=1 &
c:\Progra~1\Mozill~1\Firefox.exe -p system
http://bugzilla.mozilla.org/attachment.cgi?id=212413"

UNFORTUNATELY, Firefox does not see the USERPROFILE environment
variable even though it has been correctly written (actually, I could
have written it the long way, too, without quotes, and it would get
written, but Firefox exhibits the same problem - it just doesn't see
USERPROFILE set via AT in this way).

The observed behaviour is that Firefox comes up asking which profile
I'd like to use (since it doesn't see the directory set in
USERPROFILE). If I dismiss this new Firefox (by the way, this FF is
being run under SYSTEM), then the command window is still up, so I
check to make sure USERPROFILE is set with
SET USERPROFILE
Then I type in
SET USERPROFILE=C:\Docume~1\PeterG~1
and I can now invoke FF with no problem using the above
c:\Progra~1\Mozill~1\Firefox.exe -p system
http://bugzilla.mozilla.org/attachment.cgi?id=212413


So the issue appears to be that there are four different types of
Environment variables (System, Process, User, and Volatile), and FF is
looking for a different type than what I get when I issue the SET in
the vanilla fashion from the AT command.

My question is whether there is another way to set an environment
variable with the AT command (perhaps by something like where the
output of echo is evaluated?).

Thanks,
Csaba Gabor from Vienna

Here is my current awful, but working, method (it's awful because I
shouldn't have to invoke php. It's presumptious to suppose that
someone else will have it, even if it is great, free software):
AT 18:36 php -r
"putenv('USERPROFILE=C:\Docume~1\PeterG~1');putenv('MOZ_NO_REMOTE=1');system('c:\Progra~1\Mozill~1\Firefox.exe
-p system http://bugzilla.mozilla.org/attachment.cgi?id=212413');"
 
Sorry if you are seeing this message twice. This is the correct one.
The previous one was inadvertently posted from another account.

Clay, I appreciate your ideas - they were helpful. Now I've run into
an additional problem (unrelated to the original one) which I'm not
sure how to handle, detailed below.

Clay said:
....

The first option is to create a batch file to run the commands and
then schedule the batch file.

An impressive list of ideas. I'd rather not use a batch file here
because it would be cluttering up the drive and making drive
writeability assumptions. Unless there is a compelling reason (as in
there is no other way), I don't want to increase my file count. I hate
extra files.
From your response, I take it that nobody has actually managed to
preserve quotes within the AT command (I just don't understand how it
could have been released without the developer putting it in).
Another option is to find out the "short path" to Firefox.exe and use
that as quotes aren't needed.

for /f %%a in ("c:\Program Files\Mozilla Firefox\Firefox.exe") do (
set FFsPath=%%~sa)

Then call AT with %FFsPath% instead of the full path to FireFox.

I settled on this idea, and it does the trick (but keep reading for the
follow on problem). To find the short names, I did (on my Win XP Pro
system):
dir /x

It turns out that Firefox requires one additional environment variable,
USERPROFILE. No problem, thinks I, and revamp the AT command thusly:
AT 12:09 /INTERACTIVE %comspec% "/K SET
USERPROFILE=C:\Docume~1\PeterG~1 & SET MOZ_NO_REMOTE=1 &
c:\Progra~1\Mozill~1\Firefox.exe -p system
http://bugzilla.mozilla.org/attachment.cgi?id=212413"

UNFORTUNATELY, Firefox does not see the USERPROFILE environment
variable even though it has been correctly written (actually, I could
have written it the long way, too, without quotes, and it would get
written, but Firefox exhibits the same problem - it just doesn't see
USERPROFILE set via AT in this way).

The observed behaviour is that Firefox comes up asking which profile
I'd like to use (since it doesn't see the directory set in
USERPROFILE). If I dismiss this new Firefox (by the way, this FF is
being run under SYSTEM), then the command window is still up, so I
check to make sure USERPROFILE is set with
SET USERPROFILE
Then I type in
SET USERPROFILE=C:\Docume~1\PeterG~1
and I can now invoke FF with no problem using the above
c:\Progra~1\Mozill~1\Firefox.exe -p system
http://bugzilla.mozilla.org/attachment.cgi?id=212413


So the issue appears to be that there are four different types of
Environment variables (System, Process, User, and Volatile), and FF is
looking for a different type than what I get when I issue the SET in
the vanilla fashion from the AT command.

My question is whether there is another way to set an environment
variable with the AT command (perhaps by something like where the
output of echo is evaluated?).

Thanks,
Csaba Gabor from Vienna

Here is my current awful, but working, method (it's awful because I
shouldn't have to invoke php. It's presumptious to suppose that
someone else will have it, even if it is great, free software):
AT 18:36 php -r
"putenv('USERPROFILE=C:\Docume~1\PeterG~1');putenv('MOZ_NO_REMOTE=1');system('c:\Progra~1\Mozill~1\Firefox.exe
-p system http://bugzilla.mozilla.org/attachment.cgi?id=212413');"
 
Csaba said:
....
It turns out that Firefox requires one additional environment variable,
USERPROFILE. No problem, thinks I, and revamp the AT command thusly:
AT 12:09 /INTERACTIVE %comspec% "/K SET
USERPROFILE=C:\Docume~1\PeterG~1 & SET MOZ_NO_REMOTE=1 &
c:\Progra~1\Mozill~1\Firefox.exe -p system
http://bugzilla.mozilla.org/attachment.cgi?id=212413"

UNFORTUNATELY, Firefox does not see the USERPROFILE environment
variable even though it has been correctly written ....
My question is whether there is another way to set an environment
variable with the AT command (perhaps by something like where the
output of echo is evaluated?).

Ha! Got it!

AT 22:32 %comspec% "/C echo SET USERPROFILE=C:\Docume~1\PeterG~1 & SET
MOZ_NO_REMOTE=1 & c:\Progra~1\Mozill~1\Firefox.exe -p system
http://bugzilla.mozilla.org/attachment.cgi?id=212413"

The only difference between this and the above is the insertion of a
single echo before SET USERPROFILE (the /INTERACTIVE and /C vs. /K
don't count). It's not clear to me why that echo is making the
difference, but there you go.

Csaba Gabor from Vienna
 
Ha! Got it!

AT 22:32 %comspec% "/C echo SET USERPROFILE=C:\Docume~1\PeterG~1 & SET
MOZ_NO_REMOTE=1 & c:\Progra~1\Mozill~1\Firefox.exe -p system
http://bugzilla.mozilla.org/attachment.cgi?id=212413"

The only difference between this and the above is the insertion of a
single echo before SET USERPROFILE (the /INTERACTIVE and /C vs. /K
don't count). It's not clear to me why that echo is making the
difference, but there you go.

Glad you got it working Note that I didn't even try to work the
quotes out. The other options seemed more reliable as quotes, as
you've disovered, can be quirky.
Csaba Gabor from Vienna

A lovely city. I got there on business once but only had part of a
day to see the sites.

Cheers,
Clay
Clay Calvert
(e-mail address removed)
Replace "Z" with "L"
 
Csaba Gabor said:
Sorry if you are seeing this message twice. This is the correct one.
The previous one was inadvertently posted from another account.

Clay, I appreciate your ideas - they were helpful. Now I've run into
an additional problem (unrelated to the original one) which I'm not
sure how to handle, detailed below.



An impressive list of ideas. I'd rather not use a batch file here
because it would be cluttering up the drive

hmmm, one additional batch file versus having to type a long command
correctly...
and making drive
writeability assumptions.

hmmm, drive writeability assumptions versus having php installed...
Unless there is a compelling reason (as in
there is no other way), I don't want to increase my file count. I hate
extra files.

hmmm, I hate extra files versus... but I use Windows anyway...

/Al
 
Csaba Gabor said:
Csaba said:
Clay said:
... Files.

Ha! Got it!

AT 22:32 %comspec% "/C echo SET USERPROFILE=C:\Docume~1\PeterG~1 & SET
MOZ_NO_REMOTE=1 & c:\Progra~1\Mozill~1\Firefox.exe -p system
http://bugzilla.mozilla.org/attachment.cgi?id=212413"

The only difference between this and the above is the insertion of a
single echo before SET USERPROFILE (the /INTERACTIVE and /C vs. /K
don't count). It's not clear to me why that echo is making the
difference, but there you go.

I still think a batch file would be simpler, however, I don't see exactly
what the above compound command is accomplishing. The AT part of the command
is scheduling the execution of the command processor, and passing it an echo
command. Once that has been scheduled, the next SET command is executed in
the current context followed immediately by the running of the firefox
program.

/Al
 
Back
Top