question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting content and redirecting to the same file in a single command

See original GitHub issue

Prerequisites

Steps to reproduce

PS> "hello" > o
PS> (Get-Content o) > o

Expected behavior

PS> Get-Content o
hello

Actual behavior

PS> Get-Content o

Error details

No response

Environment data

PSVersion                      7.1.5
PSEdition                      Core
GitCommitId                    7.1.5
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jhoneillcommented, Oct 29, 2021

Isn’t the first thing that happens when you specify | out-file is the begin phase opens it as a new file for writing, then during the process phase get-content reads the newly empty file.

0reactions
vexx32commented, Oct 29, 2021

Given the file write operation is failing here, I would at least expect some kind of error to be given. The append scenario is worse, but I think both cases could be much better.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I use a file in a command and redirect output to ...
Basically I want to take as input text from a file, remove a line from that file, and send the output back to...
Read more >
Redirecting the content of a file to the command "echo"
I have a file named my_file.txt whose content is just the string Hello . How could I redirect its content to the command...
Read more >
Sending Both Output and Error Messages to the Same File
Use the shell syntax to redirect standard error messages to the same place as standard output. Preferred: $ both >& outfile. or: $...
Read more >
Unique sorting: Redirect output to the same file
sort command sorts your filename and with -u option, removes duplicate lines from it. then with -o option writes the output to the...
Read more >
How to manipulate files with shell redirection and pipelines ...
Here are some examples of using each operator in the order presented above. Redirect the standard output for a given command to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found