Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用C#运行Python脚本的行为很奇怪_C#_Python_Python 2.7_Cmd_Bitcoin - Fatal编程技术网

用C#运行Python脚本的行为很奇怪

用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

这个问题以前曾被问过并回答过(例如这里:),但在我的特定代码中,答案似乎对我不起作用

Github问题:

在cmd中,它可以无缝工作:

“python wallet-tool.py生成”

此命令生成一个新钱包。 它要求用户输入密码、密码确认和钱包名称

然而,我似乎没有正确地使用C代码

乍一看,这似乎很容易,但这里发生了一些不同寻常的事情

简化代码:

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