1

I've created the following C# Console Application (.NET Core 3.1) with Visual Studio:

using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            //Check if args contains anything
            if (args.Length > 0)
            {
                Console.WriteLine("args = " + args[0]);
            } else
            {
                Console.WriteLine("args is empty");
            }

            //Prevent the application from closing itself without user input
            string waiter = Console.ReadLine();
        }
    }
}

I am able to execute the application succesfully with one argument via cmd.exe: CMD Input and Output

Now I'd like to run this program with one argument via Python. I've read How to execute a program or call a system command? and tried to implement it. However, it seems that the application is not being run properly.

The python code I am using via Jupyter notebook:

import subprocess
path = "C:/Users/duykh/source/repos/ConsoleApp2/ConsoleApp2/bin/Release/netcoreapp3.1/ConsoleApp2.exe"
subprocess.Popen(path) //#Also tried with .call and .run
                        //#subprocess.Popen([path, "argumentexample"]) doesn't work either

Output:

<subprocess.Popen at 0x2bcaeba49a0>

My question would be:

Why is it not being run (properly) and how do I properly run this application with one argument?

1
  • Maybe another option is to call/run shell or cmd from Python and run the application from there? Commented Aug 19, 2021 at 10:01

1 Answer 1

0

I've answered my own question. In a nutshell: I am pretty stupid.

  1. Jupyter Notebook was running in the background and the application was being run there. That's why it didn't open a new prompt.

  2. subprocess.Popen([path, "argument example"]) seems to work well for running a console application with an argument as input.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.