Echo an echo command to batch file using CLI
Moderator: DosItHelp
Echo an echo command to batch file using CLI
I am trying to write the following batch file directly from the command line,
however am facing a problem with the following line.
The output within my batch file should be a line as follows:
echo D | xcopy %USERPROFILE%\Desktop C:\%username% /E /Y /H
However I cannot write it on my TEST.bat file, what am trying is from the CLI:
echo echo D | xcopy %USERPROFILE%\Desktop C:\%username% /E /Y /H > TEST.bat
Any ideas?
however am facing a problem with the following line.
The output within my batch file should be a line as follows:
echo D | xcopy %USERPROFILE%\Desktop C:\%username% /E /Y /H
However I cannot write it on my TEST.bat file, what am trying is from the CLI:
echo echo D | xcopy %USERPROFILE%\Desktop C:\%username% /E /Y /H > TEST.bat
Any ideas?
Re: Echo an echo command to batch file using CLI
I will merely comment that your code has other potential issues than the one that is clear.
Knowing what you are doing, and why the cmd prompt is being used, will very often change the answer
But on having a second look: this code does what your code was supposed to be doing:
To keep the literal text as you have shown it:
Knowing what you are doing, and why the cmd prompt is being used, will very often change the answer
But on having a second look: this code does what your code was supposed to be doing:
Code: Select all
echo xcopy "%USERPROFILE%\Desktop\*.*" "C:\%username%\" /E /Y /H > TEST.bat
To keep the literal text as you have shown it:
Code: Select all
echo xcopy "%%USERPROFILE%%\Desktop\*.*" "C:\%%username%%\" /E /Y /H > TEST.bat
Re: Echo an echo command to batch file using CLI
The idea is having an echo command to respond to the prompt to avoid user interaction.
This will still prompt for a confirmation, however if I use
echo D | xxxxxxxx
This will automatically respond with a D, so I basically need it to be present in the TEST.bat am creating.
This will still prompt for a confirmation, however if I use
echo D | xxxxxxxx
This will automatically respond with a D, so I basically need it to be present in the TEST.bat am creating.
Re: Echo an echo command to batch file using CLI
SDee wrote:The idea is having an echo command to respond to the prompt to avoid user interaction.
Did you test Foxidrive's code? I bet it does not prompt for user interaction.
Re: Echo an echo command to batch file using CLI
Well it is not only about this code, am looking for something more generic, so that was just an example.
Regardless of the function, I want this string to be present in a newly created batch file named TEST.bat, but using CLI
(Assuming Command.exe will require a Y to run)
echo Y | Command.exe
This works with no problems at all if I manually typed it to the batch file, however using CLI strips off the first part
INPUT TO CLI: echo echo Y | Command.exe > Test.bat
OUTPUT IN BAT: Command.exe
Regardless of the function, I want this string to be present in a newly created batch file named TEST.bat, but using CLI
(Assuming Command.exe will require a Y to run)
echo Y | Command.exe
This works with no problems at all if I manually typed it to the batch file, however using CLI strips off the first part
INPUT TO CLI: echo echo Y | Command.exe > Test.bat
OUTPUT IN BAT: Command.exe
Re: Echo an echo command to batch file using CLI
The rules for a literal output of these characters are
% => %%
^ => ^^
< => ^<
> => ^>
| => ^|
& => ^&
And if delayed expansion is enabled
! => ^^!
Regards
aGerman
% => %%
^ => ^^
< => ^<
> => ^>
| => ^|
& => ^&
And if delayed expansion is enabled
! => ^^!
Regards
aGerman
Re: Echo an echo command to batch file using CLI
SDee wrote:Well it is not only about this code, am looking for something more generic, so that was just an example.
If you want to eat steak and chips for dinner, and you ask for Brussells sprouts and spinach, what do you think you will get?
That applies to programming also.
-
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: Echo an echo command to batch file using CLI
Hi,
you're on CLI and make some tests
in your file you want anything like the successful commands in a batchfile to write in
take
use arrow key to find command and enter
your CLI-macro
Phil
you're on CLI and make some tests
in your file you want anything like the successful commands in a batchfile to write in
take
Code: Select all
set /p Line=
use arrow key to find command and enter
Code: Select all
>test.cmd cmd /v /c echo !Line!
type test.cmd
your CLI-macro
Code: Select all
set "file=test.cmd"
set "Write=set /p Line=line 2 %FILE%: &>>%File% cmd /v /c echo !Line!& find /n /v "" %File%"
%Write%
Phil