Search code examples
linuxsshwolfram-mathematica

Running a ssh command inside Mathematica


Lately I've been trying to run a shell ssh command from a Mathematica notebook. I tried several suggested methods with no positive outcome. My search to an answer lead me to the following result:

RunProcess[$SystemShell, All, " ssh <login>@<server> exit "]

but this gives a following error

<|"ExitCode" -> 127, "StandardOutput" -> "", "StandardError" -> "ssh: /usr/local/Wolfram/Mathematica/10.0/SystemFiles/Libraries/\ Linux-x86-64/libcrypto.so.1.0.0: no version information available \ (required by ssh) ssh: /usr/local/Wolfram/Mathematica/10.0/SystemFiles/Libraries/\ Linux-x86-64/libcrypto.so.1.0.0: no version information available \ (required by ssh) ssh: relocation error: ssh: symbol EVP_aes_128_ctr, version \ OPENSSL_1.0.1 not defined in file libcrypto.so.1.0.0 with link time \ reference "|>

do you have an idea how to fix it?

P.S. My overall goal is to import and export data between external server and Mathematica notebook.


Solution

  • Łukasz Gładczuk suggestion should work, but there is a better way to accomplish this.

    RunProcess provides a ProcessEnvironment option that allows you to set environment variables for your process. The default value is Inherited, which means the environment variables are inherited from Wolfram Language, which is what is causing library problems.

    Run echo $PATH in a terminal to find your path, then use:

    RunProcess[{"ssh", "user@server"}, ProcessEnvironment -> <|"PATH" -> yourpath|>]
    

    where yourpath is your path, as a string.