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
http://docs.platformio.org/en/latest/projectconf/section_env_build.html#dynamic-build-flags 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 = 
  ${common.build_flags_common}
  -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.

Import("env")

print("Enter a PJON ID number: ")
num1 = int(input())
env.Append(CPPDEFINES=[
  ("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?