Calling a Command with Multiple User Inputs from System Exec.vi

Updated May 27, 2025

Reported In

Software

  • LabVIEW

Issue Details

I would like to run an external command such as a Python script, but this command expects the user to interactively type in the inputs multiple times in the command prompt. If I already know all inputs in advance, is it possible to run this command from LabVIEW using System Exec.vi?

Solution

Yes, we can use System Exec.vi to execute a command that expects multiple inputs. Take for example the Python script below that expects two user inputs in a single execution. 

def get_user_choice():
    while True:
        user_input = input("Please enter 'Yes' or 'No': ").strip().lower()
        if user_input in ['yes', 'no']:
            return user_input
        else:
            print("Invalid input. Please try again.")

# Usage
choice = get_user_choice()
print(f"You selected: {choice.capitalize()}")
choice = get_user_choice()
print(f"You selected: {choice.capitalize()}")

Notice that this script is calling get_user_choice() function twice, so the user must enter "Yes" or "No" or any other string at least twice for this script to end execution. 

A manual execution of this script in Windows Command Prompt would yield this result:

In order to yield the same result in LabVIEW, we can use System Exec.vi and wire the user inputs to "standard input" terminal with a line feed (\n or ASCII 0xA) in between each input. 

 

Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.

 

When the VI above is executed, you should get the following result.