Powershell在回显到文件时生成未知字符
我正在尝试使用 Powershell 将 3 行纯文本行回显到文件中:
I am trying to echo 3 plain-text lines to a file using Powershell:
echo "#Generated" > psftp.scp
echo "put test.txt" >> psftp.scp
echo "quit" >> psftp.scp
然后我使用 psftp.exe 批处理模式来运行该文件(在 SFTP 中执行命令),但是 psftp 看到无效字符时出错:
I then use psftp.exe batch mode to run the file (executes the commands in SFTP), but psftp errors out seeing an invalid character:
psftp: unknown command " ■#"
我错过了什么?我可以在 Windows 记事本中手动输入文件,它 (psftp) 可以工作.无论我如何将第一行更改为 (#Generated
),第一部分中的块符号都会出现此错误.
What am I missing? I can manually type up the file in Windows Notepad and it (psftp) works. No matter what I change the first line to (#Generated
) it gets this error with the block symbol in the first part.
我试过在 NotePad++ 中查看文件,打开显示所有符号",但只看到 CR &LF 在行尾,这是正常的.
I've tried viewing the file in NotePad++ w/ "Show All Symbols" on, but only saw CR & LF at the end of lines which is normal.
尝试使用 set/add-content 而不是重定向.您可能还需要设置编码.
Try using set/add-content instead of redirection. You might also need to set the encoding.
"#Generated" | set-content psftp.scp -Encoding Ascii
"put test.txt" | add-content psftp.scp -Encoding Ascii
"quit" | add-content psftp.scp -Encoding Ascii