Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"copy con" or "type con > " equivalent in Powershell?

On Command Prompt you can create a text file inline by doing this:

copy con file.txt
Hello World
^Z

Or:

type con > file.txt
Hello World
^Z

Is there an equivalent command in Powershell? Neither of the two commands I listed above work.

like image 977
Govind Parmar Avatar asked Jun 23 '17 13:06

Govind Parmar


People also ask

What is copy CON command?

COPY is usually used to copy one or more files from one location to another. However, COPY can also be used to create new files. By copying from the keyboard console (COPY CON:) to the screen, files can be created and then saved to disk. The first filename you enter is referred to as the source file.

How do you copy something in PowerShell?

PowerShell provides the support of keyboard shortcut keys “CTRL+C” and “CTRL+V'. Moreover, you can right-click on the pane to paste the data into PowerShell.

How do I select and copy in PowerShell?

Use the mouse to select the text to be copied, then press Enter or right-click on the selected text to copy it to the clipboard. You need to enable QuickEdit Mode on the Options tab of the PowerShell Properties dialog box to take advantage of this feature.

What is the equivalent of which in PowerShell?

Use gcm as the Equivalent of Which Command in PowerShell You can use the gcm alias as the equivalent of which command in PowerShell. It prints the same output as Get-Command .

What does copy CON command do in MS DOS?

Copy con is an MS-DOS and Windows command line command that allows the creation of a file through the command line. To use this command, type "copy con" followed by the name of the file you want to create, as shown below. After this command is typed, you are returned to a blank line, which is the start of your file.


1 Answers

Pipe content to the out-file cmdlet to emulate this.

"Hello World" | out-file hello.txt

To get multiple lines, open the quotes but don't close them right away

"hello
>> is it me you're looking for" | out-file hello2.txt

The >> will appear on the second line after hitting enter

Another way is using "here-strings" for this instead of opening quotes.

@'
hello
is it me you're looking for?
I can even use ' @ $blabla etc in here
and no substitutes will be placed
You want var substitutes, use @"..."@ instead of @'...'@
'@ | out-file hello.txt
like image 130
alroc Avatar answered Sep 21 '22 16:09

alroc