PlatformIO Community

User input in build script

I want to collect user input before building, build_flag scripts won’t wait for user input. The pre-script does wait for user input, but does not show the message, so input("please insert id: ") does not print the inside of the input message. Anyway to better handle this?

It seems that knowing issue. Could you try input("please insert id: \n")?

I would like to achieve this but there is very little background. could @ivankravets maybe add an example to the showing how to parse a user input at compile time to a build_flag. thank you:)

@ivankravets. I still cannot figure out how to do this.

I would like the build script to pause and wait for user input. I have tried below and various versions of it but cannot get it to work. Any chance of a full example?

build_flags = 
  -D DEBUG_CODE="Serial" 
  -D SIMULATE=true
  -D TEST_FLAG=input("please insert id: \n")
  -D TEST_FLAG2=$(input("please insert id: \n"))

My solution here was to use the pre-script as it does wait for user input.

ah ok… got it to work. using the env build script as an example. thank you

It should work with the latest PIO Core 4.0. Could you try development version?

pio upgrade --dev

to which bit are you referring?
-D TEST_FLAG=input("please insert id: \n")

We don’t parse CPP macros. You need manually using extra scripting declare this macro on-the-flight.

that’s what i managed to get working.


print("Enter a PJON ID number: ")
num1 = int(input())
  ("PJON_ID", num1)

This works perfectly.

1 Like

and this is the right solution :slight_smile:

1 Like

Does not work here, with version 4.0.0rc1

> & C:/Users/FooBar/.platformio/penv/Scripts/activate.ps1
> Enter a PJON ID number:
>   File "<string>", line 1
>     & C:/Users/FooBar/.platformio/penv/Scripts/activate.ps1
>     ^
> SyntaxError: invalid syntax

It seems like an issue with your shell. Could you try classic CMD if you use Windows?

This does not appear to work in the current version of PIO!

Any suggestions for a fix?

This does not work with latest version of vscode

See docs