pythonbashimagebase64

How can I pass a base64 string as a parameter of a Python script?


I am trying to pass as a parameter in a python script a string in base 64.

I'm using Pycharm, and when I try to send it as a parameter I get the following:

Error running 'preprocess_image': Cannot run program "C:\ProgramData\Anaconda3\python.exe" (in directory "...."): CreateProcess error=206, Filename or extension is too long

It's logical, because base64 string is too big.

I'm tried using bash, but when i execute:

python preprocess_image.py --image base64String

This return nothing....

I've been looking for a while and I have not found any solution...

Any ideas?


Solution

  • You could put the base64 string in a file, and pass that filename to your python script.

    Or you could pass it via stdin :

    import sys
    print(sys.stdin.readlines())
    
    # echo "hello" | python preprocess_image.py
    # => ['hello\n']