[Python] C program crashes on windows when run from Python program

Discussão em 'Python' iniciado por Stack, Maio 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to run a C program from a Python program using subprocess.run() on Windows 11. However when the C program is run using subprocess.run() the C program does not run and returns 3221225781. But when I run the C program directly and not from python it runs fine and prints "Hello World!". Looking online 3221225781 means STATUS_DLL_NOT_FOUND. I've tried compiling the C program statically so it doesn't require any DLLs using gcc -static -static-libgcc -o test.exe test.c but I still get the same STATUS_DLL_NOT_FOUND error. The C program is being compiled using gcc installed from mingw.

    test.c

    #include <stdio.h>

    int main() {
    printf("Hello World!");
    return 0;
    }


    test.py

    import subprocess

    if __name__ == '__main__':
    prog = "./test.exe"
    result = subprocess.run(prog)
    print(result)

    Continue reading...

Compartilhe esta Página