用C#运行Python脚本的行为很奇怪
这个问题以前曾被问过并回答过(例如这里:),但在我的特定代码中,答案似乎对我不起作用 Github问题: 在cmd中,它可以无缝工作: “python wallet-tool.py生成” 此命令生成一个新钱包。 它要求用户输入密码、密码确认和钱包名称 然而,我似乎没有正确地使用C代码 乍一看,这似乎很容易,但这里发生了一些不同寻常的事情 简化代码:用C#运行Python脚本的行为很奇怪,c#,python,python-2.7,cmd,bitcoin,C#,Python,Python 2.7,Cmd,Bitcoin,这个问题以前曾被问过并回答过(例如这里:),但在我的特定代码中,答案似乎对我不起作用 Github问题: 在cmd中,它可以无缝工作: “python wallet-tool.py生成” 此命令生成一个新钱包。 它要求用户输入密码、密码确认和钱包名称 然而,我似乎没有正确地使用C代码 乍一看,这似乎很容易,但这里发生了一些不同寻常的事情 简化代码: internal string Generate() { ProcessStartInfo start = new ProcessStart
internal string Generate()
{
ProcessStartInfo start = new ProcessStartInfo
{
FileName = PythonPath,
Arguments = "wallet-tool.py generate",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardInput = true
};
using (var process = Process.Start(start))
{
if (process == null) return String.Empty;
using (var output = process.StandardOutput)
{
using (var input = process.StandardInput)
{
// Asks for password.
var result = output.ReadToEnd();
input.WriteLine("password");
// Asks for password confirmation.
result += output.ReadToEnd();
input.WriteLine("password");
// Asks for wallet file name.
result += output.ReadToEnd();
input.WriteLine("wallet.json");
result += output.ReadToEnd();
return result;
}
}
}
}
作为替代,我改为IronPython