What is a command that will write a command to a file? [duplicate]











up vote
1
down vote

favorite













This question already has an answer here:




  • How can I add greater than and less than into a batch file variable

    3 answers




I would like to make a batch file that writes a command to a batch file. I have tried using



@echo "@echo this is a test>test.txt">testBat.bat


Which gives me the output in testBat.bat of:



"@echo this is a test>test.txt" 


This issue is, it still has the quotations around it in the batch file, and running it without the quotes gives me:



"this is a test" 


So running it without the quotes just puts the text in the batch file. And after spending a half an hour looking I couldn't find if this was at all possible.










share|improve this question









New contributor




Randy Titler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











marked as duplicate by phuclv, aschipfl batch-file
Users with the  batch-file badge can single-handedly close batch-file questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 at 18:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1




    Escaping characters like ", <, >, >>, or | in the arguments to a batch file, Batch character escaping, Escape percent in bat file, Escape special character in a windows batch, Special Characters in Batch File
    – phuclv
    Nov 18 at 14:51















up vote
1
down vote

favorite













This question already has an answer here:




  • How can I add greater than and less than into a batch file variable

    3 answers




I would like to make a batch file that writes a command to a batch file. I have tried using



@echo "@echo this is a test>test.txt">testBat.bat


Which gives me the output in testBat.bat of:



"@echo this is a test>test.txt" 


This issue is, it still has the quotations around it in the batch file, and running it without the quotes gives me:



"this is a test" 


So running it without the quotes just puts the text in the batch file. And after spending a half an hour looking I couldn't find if this was at all possible.










share|improve this question









New contributor




Randy Titler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











marked as duplicate by phuclv, aschipfl batch-file
Users with the  batch-file badge can single-handedly close batch-file questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 at 18:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1




    Escaping characters like ", <, >, >>, or | in the arguments to a batch file, Batch character escaping, Escape percent in bat file, Escape special character in a windows batch, Special Characters in Batch File
    – phuclv
    Nov 18 at 14:51













up vote
1
down vote

favorite









up vote
1
down vote

favorite












This question already has an answer here:




  • How can I add greater than and less than into a batch file variable

    3 answers




I would like to make a batch file that writes a command to a batch file. I have tried using



@echo "@echo this is a test>test.txt">testBat.bat


Which gives me the output in testBat.bat of:



"@echo this is a test>test.txt" 


This issue is, it still has the quotations around it in the batch file, and running it without the quotes gives me:



"this is a test" 


So running it without the quotes just puts the text in the batch file. And after spending a half an hour looking I couldn't find if this was at all possible.










share|improve this question









New contributor




Randy Titler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












This question already has an answer here:




  • How can I add greater than and less than into a batch file variable

    3 answers




I would like to make a batch file that writes a command to a batch file. I have tried using



@echo "@echo this is a test>test.txt">testBat.bat


Which gives me the output in testBat.bat of:



"@echo this is a test>test.txt" 


This issue is, it still has the quotations around it in the batch file, and running it without the quotes gives me:



"this is a test" 


So running it without the quotes just puts the text in the batch file. And after spending a half an hour looking I couldn't find if this was at all possible.





This question already has an answer here:




  • How can I add greater than and less than into a batch file variable

    3 answers








batch-file cmd






share|improve this question









New contributor




Randy Titler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Randy Titler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 18 at 1:11









Nick

19.1k51433




19.1k51433






New contributor




Randy Titler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 18 at 1:07









Randy Titler

83




83




New contributor




Randy Titler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Randy Titler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Randy Titler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




marked as duplicate by phuclv, aschipfl batch-file
Users with the  batch-file badge can single-handedly close batch-file questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 at 18:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by phuclv, aschipfl batch-file
Users with the  batch-file badge can single-handedly close batch-file questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 18 at 18:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1




    Escaping characters like ", <, >, >>, or | in the arguments to a batch file, Batch character escaping, Escape percent in bat file, Escape special character in a windows batch, Special Characters in Batch File
    – phuclv
    Nov 18 at 14:51














  • 1




    Escaping characters like ", <, >, >>, or | in the arguments to a batch file, Batch character escaping, Escape percent in bat file, Escape special character in a windows batch, Special Characters in Batch File
    – phuclv
    Nov 18 at 14:51








1




1




Escaping characters like ", <, >, >>, or | in the arguments to a batch file, Batch character escaping, Escape percent in bat file, Escape special character in a windows batch, Special Characters in Batch File
– phuclv
Nov 18 at 14:51




Escaping characters like ", <, >, >>, or | in the arguments to a batch file, Batch character escaping, Escape percent in bat file, Escape special character in a windows batch, Special Characters in Batch File
– phuclv
Nov 18 at 14:51












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Try this:



@echo @echo this is a test^>test.txt>testBat.bat


I vaguely remember that cmd uses ^ as an escape character.






share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    Try this:



    @echo @echo this is a test^>test.txt>testBat.bat


    I vaguely remember that cmd uses ^ as an escape character.






    share|improve this answer

























      up vote
      1
      down vote



      accepted










      Try this:



      @echo @echo this is a test^>test.txt>testBat.bat


      I vaguely remember that cmd uses ^ as an escape character.






      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        Try this:



        @echo @echo this is a test^>test.txt>testBat.bat


        I vaguely remember that cmd uses ^ as an escape character.






        share|improve this answer












        Try this:



        @echo @echo this is a test^>test.txt>testBat.bat


        I vaguely remember that cmd uses ^ as an escape character.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 18 at 1:18









        melpomene

        56.3k54387




        56.3k54387















            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin