from RPi import GPIO
global ON
global OFF
GPIO.setup(21, GPIO.OUT)
x = open(testo.txt")
if x.read() == "true":
    GPIO.output(21, ON)
    GPIO.output(21, OFF)

I need to set high/low an output of my raspberry pi 4 from windows .bat file. Inside the .bat file I create a text file containing either true or false. If the text is true the output goes high, if it is false it goes low.

My program reads the contents of the file but the IF doesn't work; it read only the content of the ELSE, even if the text file contains true. do you know why?

  • Are you running Windows on the Pi? If you are using Raspberry Pi OS why not just use a Linux batch file. Why do you mention Windows?
    – joan
    Dec 16, 2022 at 10:07
  • i have a windows pc where i start the batch file. the batch file create the file txt and send it to raspberry pi. Dec 16, 2022 at 10:09
  • The file is nonsense and would generate error messages. Why don't you fix them?
    – Milliways
    Dec 16, 2022 at 10:26
  • @Milliways where is the error, can you help me? it's my first time with raspberry pi... Dec 16, 2022 at 10:30
  • 1
    open(testo.txt") and it is far from clear what x.read() would produce. As you have posted no output of attempting to run your program who knows? This looks like a programming question - nothing specific to Pi.
    – Milliways
    Dec 16, 2022 at 11:14


Your Answer

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

Browse other questions tagged or ask your own question.