0

I can mount (in the fxce4-terminal) successfully with something like:

sshfs -o password_stdin user@example.ddnss.de:/remote/path ~/example_local_path/ <<< 'password'

but not (in a python3-Terminal or an python3-script):

import os
os.system("sshfs -o password_stdin user@example.ddnss.de:/remote/path ~/example_local_path/ <<< 'password'")

the latter return an Syntax error: redirection unexpected

Why fails the command when called from python, while it works from the terminal? Please help!

1 Answers1

0

The here-string syntax you tried to use is Bash-specific; os.system() runs sh.

You're better off using subprocess anyway, as also recommended by the os.system() documentation.

import subprocess

subprocess.check_call(
    ["sshfs", "-o", "password_stdin",
      "user@example.ddnss.de:/remote/path", 
      "~/example_local_path/"],
    input='password', text=True)

Splitting the command into a list of tokens removes the need for shell=True which you generally want to avoid, especially if you aren't very familiar with the shell. See also Actual meaning of shell=True in subprocess

tripleee
  • 175,061
  • 34
  • 275
  • 318