Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:47:20+00:00 2026-06-13T21:47:20+00:00

I am running a python script on a windows machine to invoke another python

  • 0

I am running a python script on a windows machine to invoke another python script on a remote linux machine. I am using subprocess.call with ssh to do this, like below:
subprocess.call('ssh -i <identify file> username@hostname python <script_on_linux_machine>') and this works fine.

However, if I want to set some environment variables, like below:
subprocess.call('ssh -i <identify file> username@hostname python <script_on_linux_machine>', env={key1:value1}) it fails.
I get the following error:
ssh_connect: getnameinfo failed
ssh: connect to host <hostname> port 22: Operation not permitted
255

I’ve tried splitting the ssh commands into list and passing. Didn’t help.
I’ve tried to run other ‘local'(windows) commands thru subprocess.call() and tried setting the env. It works fine.
I’ve tried to run other commands(such as ls) on the remote linux machine. Again, subprocess.call() works fine, as long as I don’t try to set the environment.

What am I doing wrong? Would I be able to set the environment for a python script on a remote machine? Any help will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:47:22+00:00Added an answer on June 13, 2026 at 9:47 pm

    To set the environment on the remote side, you will need to do calls on the remote side. Try writing and uploading a wrapper script which does this env setting, e.g.

    import subprocess
    import sys
    
    
    args = sys.argv[1:]
    env = dict(zip(args[::2], args[1::2]))
    
    subprocess.call(['python', 'script.py'], env=env)
    

    Now you just have to pass this information in your original call, e.g.

    subprocess.call('ssh -i <identify file> username@hostname '
                    'python <script_on_linux_machine> %s %s' % (key, value))
    

    Or some more extensible method of converting a dict to the required format.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running several instances of a certain Python script on a Windows machine, each
I tried running a python script: print Hello, World! And I get this error:
I have a Python script that is running a few ls commands. This script
I'd like to prevent multiple instances of the same long-running python command-line script from
I'm using this tool to set up a ssh server on Windows. I'm trying
I'm running Python 3.1 on Windows and I'm trying to distribute my Pygame script
When running any Python script (by double clicking a .py file on Windows 7)
I am on a Windows 7 machine, using Python 2.7. I created a virtual
Running Python 2.5 on Windows XP SP2. When I run a Python script that
I am running some shell test scripts from a python script under Windows. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.