0

I want to type directly into the Powershell prompt too, not pipe in a text file.

Foo`r doesn't work for me. For example:

echo "RJ`r`n" | .\nc.exe -u  192.168.1.247 2639

but what I'd really like to do is just

.\nc.exe -u  192.168.1.247 2639

then start typing into the prompt.

4

1 回答 1

1

尝试:

"Foo`ndoes work for me"

如果您需要完整的 CRLF 序列,则:

"Foo`r`ndoes work for me"

请注意,转义字符仅适用于双引号字符串 - 而不是单引号字符串。

更新:目前 PowerShell 不支持重定向<输入,因此您只能使用管道从交互式提示中获取标准输入到 exe。nc.exe 是否可能期望另一个字符(或转义字符)来终止输入?我知道控制台 exe 可以从 PowerShell 接收标准输入。如果您有 C# 编译器,则可以通过编译以下源代码 (csc echostdin.cs) 来查看这一点:

using System;
public class App
{
  public static void Main()
  {
    int ch;
    while ((ch = Console.In.Read()) != -1)
    {
      Console.Write((char)ch);
    }
  }
}

然后执行exe:

PS> "foo`r`n" | .\echostdin.exe
foo

PS>
于 2010-03-29T22:40:12.667 回答