-1

This question have been asked and answered before (for example here: How do I run a Python script from C#?), but in my specific code the answers doesn't seem to work for me.

Github issue: https://github.com/nopara73/JoinMarketTest/issues/2

In cmd it seamlessly works:

"python wallet-tool.py generate"

This command generates a new wallet. It asks for password, password confirmation and wallet name from the user.

However I doesn't seem to get it right with C# code.

At first glance it seems like an easy one, but something unusual is happening here.

The simpified code:

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;
                    }
                }
            }
}
Community
  • 1
  • 1
nopara73
  • 502
  • 6
  • 24

1 Answers1

0

As an alternative I've changed to IronPython.

nopara73
  • 502
  • 6
  • 24