7z in batch file with variables “Incorrect command line”
I'm trying to run the following batch file:
set HH=%time:~0,2%
set HH=%HH: =0%
IF %time:~0,2% GTR 5 (
IF %time:~0,2% LSS 21 (
FOR /F "TOKENS=1 DELIMS=:" %%A IN ('TIME/T') DO SET HH=%%A
XCOPY "D:Sage RAM ImageSage Data" C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-%HH% /D /Y /E /R /K /C /H /I
"C:Program Files7-Zip7z.exe" -a -pXXXX C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-%HH%sage-backup.zip C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-%HH%*
EXIT /B 0
)
)
But it keeps giving me the error "Incorrect command line". I think it might have something to do with the date variables, as they work fine in normal XCOPY operations.
Where is it wrong?
When echoing the line I get:
"C:Program Files7-Zip7z.exe" -a -p3uropeaN1 C:Sage-Incremental-Backupsage-2
014-06-10-hour-07sage-backup.zip C:Sage-Incremental-Backupsage-2014-06-10-hou
r-07*
windows-7 backup batch batch-file 7-zip
add a comment |
I'm trying to run the following batch file:
set HH=%time:~0,2%
set HH=%HH: =0%
IF %time:~0,2% GTR 5 (
IF %time:~0,2% LSS 21 (
FOR /F "TOKENS=1 DELIMS=:" %%A IN ('TIME/T') DO SET HH=%%A
XCOPY "D:Sage RAM ImageSage Data" C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-%HH% /D /Y /E /R /K /C /H /I
"C:Program Files7-Zip7z.exe" -a -pXXXX C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-%HH%sage-backup.zip C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-%HH%*
EXIT /B 0
)
)
But it keeps giving me the error "Incorrect command line". I think it might have something to do with the date variables, as they work fine in normal XCOPY operations.
Where is it wrong?
When echoing the line I get:
"C:Program Files7-Zip7z.exe" -a -p3uropeaN1 C:Sage-Incremental-Backupsage-2
014-06-10-hour-07sage-backup.zip C:Sage-Incremental-Backupsage-2014-06-10-hou
r-07*
windows-7 backup batch batch-file 7-zip
The value set to the variableHH
on the second line seems wrong. Why are you assigning a value to theHH
variable and changing it back immediately in the next line?
– Chirag Bhatia - chirag64
Jun 4 '14 at 5:22
Putecho
in front of the line and report here what’s getting printed. @Chirag64 The second line removes space characters from the string. Nothing wrong or strange about it.
– Daniel B
Jun 4 '14 at 5:46
you need to usesetlocal enabledelayedexpansion
and change this line to:XCOPY "D:Sage RAM ImageSage Data" C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-!HH! /D /Y /E /R /K /C /H /
– Alex
Jun 4 '14 at 21:21
@DanielB Please see my edit for the output.
– imperium2335
Jun 10 '14 at 6:06
add a comment |
I'm trying to run the following batch file:
set HH=%time:~0,2%
set HH=%HH: =0%
IF %time:~0,2% GTR 5 (
IF %time:~0,2% LSS 21 (
FOR /F "TOKENS=1 DELIMS=:" %%A IN ('TIME/T') DO SET HH=%%A
XCOPY "D:Sage RAM ImageSage Data" C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-%HH% /D /Y /E /R /K /C /H /I
"C:Program Files7-Zip7z.exe" -a -pXXXX C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-%HH%sage-backup.zip C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-%HH%*
EXIT /B 0
)
)
But it keeps giving me the error "Incorrect command line". I think it might have something to do with the date variables, as they work fine in normal XCOPY operations.
Where is it wrong?
When echoing the line I get:
"C:Program Files7-Zip7z.exe" -a -p3uropeaN1 C:Sage-Incremental-Backupsage-2
014-06-10-hour-07sage-backup.zip C:Sage-Incremental-Backupsage-2014-06-10-hou
r-07*
windows-7 backup batch batch-file 7-zip
I'm trying to run the following batch file:
set HH=%time:~0,2%
set HH=%HH: =0%
IF %time:~0,2% GTR 5 (
IF %time:~0,2% LSS 21 (
FOR /F "TOKENS=1 DELIMS=:" %%A IN ('TIME/T') DO SET HH=%%A
XCOPY "D:Sage RAM ImageSage Data" C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-%HH% /D /Y /E /R /K /C /H /I
"C:Program Files7-Zip7z.exe" -a -pXXXX C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-%HH%sage-backup.zip C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-%HH%*
EXIT /B 0
)
)
But it keeps giving me the error "Incorrect command line". I think it might have something to do with the date variables, as they work fine in normal XCOPY operations.
Where is it wrong?
When echoing the line I get:
"C:Program Files7-Zip7z.exe" -a -p3uropeaN1 C:Sage-Incremental-Backupsage-2
014-06-10-hour-07sage-backup.zip C:Sage-Incremental-Backupsage-2014-06-10-hou
r-07*
windows-7 backup batch batch-file 7-zip
windows-7 backup batch batch-file 7-zip
edited Jun 10 '14 at 6:06
imperium2335
asked Jun 4 '14 at 5:20
imperium2335imperium2335
10112
10112
The value set to the variableHH
on the second line seems wrong. Why are you assigning a value to theHH
variable and changing it back immediately in the next line?
– Chirag Bhatia - chirag64
Jun 4 '14 at 5:22
Putecho
in front of the line and report here what’s getting printed. @Chirag64 The second line removes space characters from the string. Nothing wrong or strange about it.
– Daniel B
Jun 4 '14 at 5:46
you need to usesetlocal enabledelayedexpansion
and change this line to:XCOPY "D:Sage RAM ImageSage Data" C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-!HH! /D /Y /E /R /K /C /H /
– Alex
Jun 4 '14 at 21:21
@DanielB Please see my edit for the output.
– imperium2335
Jun 10 '14 at 6:06
add a comment |
The value set to the variableHH
on the second line seems wrong. Why are you assigning a value to theHH
variable and changing it back immediately in the next line?
– Chirag Bhatia - chirag64
Jun 4 '14 at 5:22
Putecho
in front of the line and report here what’s getting printed. @Chirag64 The second line removes space characters from the string. Nothing wrong or strange about it.
– Daniel B
Jun 4 '14 at 5:46
you need to usesetlocal enabledelayedexpansion
and change this line to:XCOPY "D:Sage RAM ImageSage Data" C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-!HH! /D /Y /E /R /K /C /H /
– Alex
Jun 4 '14 at 21:21
@DanielB Please see my edit for the output.
– imperium2335
Jun 10 '14 at 6:06
The value set to the variable
HH
on the second line seems wrong. Why are you assigning a value to the HH
variable and changing it back immediately in the next line?– Chirag Bhatia - chirag64
Jun 4 '14 at 5:22
The value set to the variable
HH
on the second line seems wrong. Why are you assigning a value to the HH
variable and changing it back immediately in the next line?– Chirag Bhatia - chirag64
Jun 4 '14 at 5:22
Put
echo
in front of the line and report here what’s getting printed. @Chirag64 The second line removes space characters from the string. Nothing wrong or strange about it.– Daniel B
Jun 4 '14 at 5:46
Put
echo
in front of the line and report here what’s getting printed. @Chirag64 The second line removes space characters from the string. Nothing wrong or strange about it.– Daniel B
Jun 4 '14 at 5:46
you need to use
setlocal enabledelayedexpansion
and change this line to: XCOPY "D:Sage RAM ImageSage Data" C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-!HH! /D /Y /E /R /K /C /H /
– Alex
Jun 4 '14 at 21:21
you need to use
setlocal enabledelayedexpansion
and change this line to: XCOPY "D:Sage RAM ImageSage Data" C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-!HH! /D /Y /E /R /K /C /H /
– Alex
Jun 4 '14 at 21:21
@DanielB Please see my edit for the output.
– imperium2335
Jun 10 '14 at 6:06
@DanielB Please see my edit for the output.
– imperium2335
Jun 10 '14 at 6:06
add a comment |
1 Answer
1
active
oldest
votes
It seems the -a
switch was wrong. I removed the -a
and replaced with just a
and it worked ☺.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f763342%2f7z-in-batch-file-with-variables-incorrect-command-line%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It seems the -a
switch was wrong. I removed the -a
and replaced with just a
and it worked ☺.
add a comment |
It seems the -a
switch was wrong. I removed the -a
and replaced with just a
and it worked ☺.
add a comment |
It seems the -a
switch was wrong. I removed the -a
and replaced with just a
and it worked ☺.
It seems the -a
switch was wrong. I removed the -a
and replaced with just a
and it worked ☺.
answered Jun 10 '14 at 6:08
imperium2335imperium2335
10112
10112
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f763342%2f7z-in-batch-file-with-variables-incorrect-command-line%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The value set to the variable
HH
on the second line seems wrong. Why are you assigning a value to theHH
variable and changing it back immediately in the next line?– Chirag Bhatia - chirag64
Jun 4 '14 at 5:22
Put
echo
in front of the line and report here what’s getting printed. @Chirag64 The second line removes space characters from the string. Nothing wrong or strange about it.– Daniel B
Jun 4 '14 at 5:46
you need to use
setlocal enabledelayedexpansion
and change this line to:XCOPY "D:Sage RAM ImageSage Data" C:Sage-Incremental-Backupsage-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour-!HH! /D /Y /E /R /K /C /H /
– Alex
Jun 4 '14 at 21:21
@DanielB Please see my edit for the output.
– imperium2335
Jun 10 '14 at 6:06