在cmd能执行却在powershell不能执行的问题


PowerShell交流中心在cmd能执行却在powershell不能执行的问题
0
yongguangl asked 6 年 ago

在 cmd 控制台中,我可以使用 C:\Users\liuyongg\source> file <input_file>out_file 命令,其中 file 是一个 file.exe,C++编译出来的可执行文件;这条命令可以读取 input_file 中的内容到 file.exe 中,并把 file.exe 的执行结果,放到一个叫 out_file 的文件中去。但我在Power shell执行这条指令会得到一个问题:“<”运算符是为将来使用而保留的。请问我应该用什么的命令替换cmd中的这条命令,谢谢。
 

Kono replied 6 年 ago

读取文本信息也可以用.net试一下比如:[io.file]::ReadAllLines(” C:\Windows\System32\drivers\etc\hosts “) > your.txt

1 Answers
0
Mooser Lee 管理员 answered 6 年 ago
Get-Content  C:\Windows\System32\drivers\etc\hosts | Out-File your.txt
yongguangl replied 6 年 ago

非常感谢Lee的回答,我在此完善一下我的指令,Get-Content input_file | ./file | Out-File out_file.txt ,意思是将input_file文件中的内容读取到 file.exe 程序中,并将 file.exe 的执行结果输出到一个名为out_file.txt 的新文件中。在此处等价于cmd中的 file out_file指令。

yongguangl replied 6 年 ago

在此处等价于cmd中的 file out_file指令。

Mooser Lee 管理员 replied 6 年 ago

感谢分享

yongguangl replied 6 年 ago

呀,“<”号中的内容给我自动消失了啊,在此处等价于cmd中的 “file out_file” 指令,我用引号包一下试试行不行。

yongguangl replied 6 年 ago

哈哈,只能用引号单个包起来, 在此处等价于 cmd 中的 file “”out_file 指令。

yongguangl replied 6 年 ago

哎呀我去,这是个bug吗,左右一起用,里面的内容就没了。。。