PowerShell Tee-Object command with -Append












1















I run into an issue with the PowerShell 4.0 Tee-Object command (alias tee) and the command that I'm using is as follows:



powershell "cmd /c dir | Tee-Object -filepath C:1.txt -Append"


When 1.txt is an empty file, it writes the output as you see on the screen (as-is). But if 1.txt has some existing content before you run the command, it appends the output with no new lines and the files looks completely messed up.



I'm surprised to see this behavior and any thoughts would help me to proceed further. Note that I have to use the Tee-Object command as I would like to see the output on the screen when a command is running and append it to the existing log file that has some contents.










share|improve this question




















  • 1





    Running your exact commands I don't see any issue, 1.txt looks fine even after running multiple times. Question for you, why mix DOS and powershell? Might have more consistant results when working with cmdlets. gci | tee -filepath 1.txt -Append

    – Matt Gartman
    Jan 22 '16 at 23:30













  • Thanks for your quick response. I actually use this in one of my build step ( windows command) in Jenkins. cmd /c dir - picked up as an example...I actually call a perl script in it's place...Several previous steps in the job writes the output to the same file and when it comes to this powershell tee command it, it writes the output;but messes with up encoding.... If you try the command that i shared from dos command prmopt, you would see the same result that i see...

    – user2705120
    Jan 22 '16 at 23:48













  • Strange, ran it several times and 1.txt on my system seems fine, no encoding/line break issues.

    – Matt Gartman
    Jan 23 '16 at 0:29











  • Oops...I did not explain it right :-( Thanks for your time and support. This is what i exactly tried and i see an issue with the encoding that the powershell tee command uses... i tried the following commands in the order: 1. ECHO Line 1 >C:1.txt 2. ECHO Line 2 >>C:1.txt 3. ECHO Line 3 >>C:1.txt 4.powershell "cmd /c dir | tee -filepath c:1.txt -Append"

    – user2705120
    Jan 23 '16 at 0:51











  • Matt, I think, you see my issue now...

    – user2705120
    Jan 23 '16 at 0:57
















1















I run into an issue with the PowerShell 4.0 Tee-Object command (alias tee) and the command that I'm using is as follows:



powershell "cmd /c dir | Tee-Object -filepath C:1.txt -Append"


When 1.txt is an empty file, it writes the output as you see on the screen (as-is). But if 1.txt has some existing content before you run the command, it appends the output with no new lines and the files looks completely messed up.



I'm surprised to see this behavior and any thoughts would help me to proceed further. Note that I have to use the Tee-Object command as I would like to see the output on the screen when a command is running and append it to the existing log file that has some contents.










share|improve this question




















  • 1





    Running your exact commands I don't see any issue, 1.txt looks fine even after running multiple times. Question for you, why mix DOS and powershell? Might have more consistant results when working with cmdlets. gci | tee -filepath 1.txt -Append

    – Matt Gartman
    Jan 22 '16 at 23:30













  • Thanks for your quick response. I actually use this in one of my build step ( windows command) in Jenkins. cmd /c dir - picked up as an example...I actually call a perl script in it's place...Several previous steps in the job writes the output to the same file and when it comes to this powershell tee command it, it writes the output;but messes with up encoding.... If you try the command that i shared from dos command prmopt, you would see the same result that i see...

    – user2705120
    Jan 22 '16 at 23:48













  • Strange, ran it several times and 1.txt on my system seems fine, no encoding/line break issues.

    – Matt Gartman
    Jan 23 '16 at 0:29











  • Oops...I did not explain it right :-( Thanks for your time and support. This is what i exactly tried and i see an issue with the encoding that the powershell tee command uses... i tried the following commands in the order: 1. ECHO Line 1 >C:1.txt 2. ECHO Line 2 >>C:1.txt 3. ECHO Line 3 >>C:1.txt 4.powershell "cmd /c dir | tee -filepath c:1.txt -Append"

    – user2705120
    Jan 23 '16 at 0:51











  • Matt, I think, you see my issue now...

    – user2705120
    Jan 23 '16 at 0:57














1












1








1


0






I run into an issue with the PowerShell 4.0 Tee-Object command (alias tee) and the command that I'm using is as follows:



powershell "cmd /c dir | Tee-Object -filepath C:1.txt -Append"


When 1.txt is an empty file, it writes the output as you see on the screen (as-is). But if 1.txt has some existing content before you run the command, it appends the output with no new lines and the files looks completely messed up.



I'm surprised to see this behavior and any thoughts would help me to proceed further. Note that I have to use the Tee-Object command as I would like to see the output on the screen when a command is running and append it to the existing log file that has some contents.










share|improve this question
















I run into an issue with the PowerShell 4.0 Tee-Object command (alias tee) and the command that I'm using is as follows:



powershell "cmd /c dir | Tee-Object -filepath C:1.txt -Append"


When 1.txt is an empty file, it writes the output as you see on the screen (as-is). But if 1.txt has some existing content before you run the command, it appends the output with no new lines and the files looks completely messed up.



I'm surprised to see this behavior and any thoughts would help me to proceed further. Note that I have to use the Tee-Object command as I would like to see the output on the screen when a command is running and append it to the existing log file that has some contents.







powershell powershell-v3.0






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 3:43









Peter Mortensen

13.6k1984111




13.6k1984111










asked Jan 22 '16 at 23:14









user2705120user2705120

10629




10629








  • 1





    Running your exact commands I don't see any issue, 1.txt looks fine even after running multiple times. Question for you, why mix DOS and powershell? Might have more consistant results when working with cmdlets. gci | tee -filepath 1.txt -Append

    – Matt Gartman
    Jan 22 '16 at 23:30













  • Thanks for your quick response. I actually use this in one of my build step ( windows command) in Jenkins. cmd /c dir - picked up as an example...I actually call a perl script in it's place...Several previous steps in the job writes the output to the same file and when it comes to this powershell tee command it, it writes the output;but messes with up encoding.... If you try the command that i shared from dos command prmopt, you would see the same result that i see...

    – user2705120
    Jan 22 '16 at 23:48













  • Strange, ran it several times and 1.txt on my system seems fine, no encoding/line break issues.

    – Matt Gartman
    Jan 23 '16 at 0:29











  • Oops...I did not explain it right :-( Thanks for your time and support. This is what i exactly tried and i see an issue with the encoding that the powershell tee command uses... i tried the following commands in the order: 1. ECHO Line 1 >C:1.txt 2. ECHO Line 2 >>C:1.txt 3. ECHO Line 3 >>C:1.txt 4.powershell "cmd /c dir | tee -filepath c:1.txt -Append"

    – user2705120
    Jan 23 '16 at 0:51











  • Matt, I think, you see my issue now...

    – user2705120
    Jan 23 '16 at 0:57














  • 1





    Running your exact commands I don't see any issue, 1.txt looks fine even after running multiple times. Question for you, why mix DOS and powershell? Might have more consistant results when working with cmdlets. gci | tee -filepath 1.txt -Append

    – Matt Gartman
    Jan 22 '16 at 23:30













  • Thanks for your quick response. I actually use this in one of my build step ( windows command) in Jenkins. cmd /c dir - picked up as an example...I actually call a perl script in it's place...Several previous steps in the job writes the output to the same file and when it comes to this powershell tee command it, it writes the output;but messes with up encoding.... If you try the command that i shared from dos command prmopt, you would see the same result that i see...

    – user2705120
    Jan 22 '16 at 23:48













  • Strange, ran it several times and 1.txt on my system seems fine, no encoding/line break issues.

    – Matt Gartman
    Jan 23 '16 at 0:29











  • Oops...I did not explain it right :-( Thanks for your time and support. This is what i exactly tried and i see an issue with the encoding that the powershell tee command uses... i tried the following commands in the order: 1. ECHO Line 1 >C:1.txt 2. ECHO Line 2 >>C:1.txt 3. ECHO Line 3 >>C:1.txt 4.powershell "cmd /c dir | tee -filepath c:1.txt -Append"

    – user2705120
    Jan 23 '16 at 0:51











  • Matt, I think, you see my issue now...

    – user2705120
    Jan 23 '16 at 0:57








1




1





Running your exact commands I don't see any issue, 1.txt looks fine even after running multiple times. Question for you, why mix DOS and powershell? Might have more consistant results when working with cmdlets. gci | tee -filepath 1.txt -Append

– Matt Gartman
Jan 22 '16 at 23:30







Running your exact commands I don't see any issue, 1.txt looks fine even after running multiple times. Question for you, why mix DOS and powershell? Might have more consistant results when working with cmdlets. gci | tee -filepath 1.txt -Append

– Matt Gartman
Jan 22 '16 at 23:30















Thanks for your quick response. I actually use this in one of my build step ( windows command) in Jenkins. cmd /c dir - picked up as an example...I actually call a perl script in it's place...Several previous steps in the job writes the output to the same file and when it comes to this powershell tee command it, it writes the output;but messes with up encoding.... If you try the command that i shared from dos command prmopt, you would see the same result that i see...

– user2705120
Jan 22 '16 at 23:48







Thanks for your quick response. I actually use this in one of my build step ( windows command) in Jenkins. cmd /c dir - picked up as an example...I actually call a perl script in it's place...Several previous steps in the job writes the output to the same file and when it comes to this powershell tee command it, it writes the output;but messes with up encoding.... If you try the command that i shared from dos command prmopt, you would see the same result that i see...

– user2705120
Jan 22 '16 at 23:48















Strange, ran it several times and 1.txt on my system seems fine, no encoding/line break issues.

– Matt Gartman
Jan 23 '16 at 0:29





Strange, ran it several times and 1.txt on my system seems fine, no encoding/line break issues.

– Matt Gartman
Jan 23 '16 at 0:29













Oops...I did not explain it right :-( Thanks for your time and support. This is what i exactly tried and i see an issue with the encoding that the powershell tee command uses... i tried the following commands in the order: 1. ECHO Line 1 >C:1.txt 2. ECHO Line 2 >>C:1.txt 3. ECHO Line 3 >>C:1.txt 4.powershell "cmd /c dir | tee -filepath c:1.txt -Append"

– user2705120
Jan 23 '16 at 0:51





Oops...I did not explain it right :-( Thanks for your time and support. This is what i exactly tried and i see an issue with the encoding that the powershell tee command uses... i tried the following commands in the order: 1. ECHO Line 1 >C:1.txt 2. ECHO Line 2 >>C:1.txt 3. ECHO Line 3 >>C:1.txt 4.powershell "cmd /c dir | tee -filepath c:1.txt -Append"

– user2705120
Jan 23 '16 at 0:51













Matt, I think, you see my issue now...

– user2705120
Jan 23 '16 at 0:57





Matt, I think, you see my issue now...

– user2705120
Jan 23 '16 at 0:57












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34957512%2fpowershell-tee-object-command-with-append%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34957512%2fpowershell-tee-object-command-with-append%23new-answer', 'question_page');
}
);

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







這個網誌中的熱門文章

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Xamarin.form Move up view when keyboard appear

JBPM : POST request for execute process go wrong