Getting content and redirecting to the same file in a single command
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
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:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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.