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 6675369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:50:49+00:00 2026-05-26T03:50:49+00:00

I’m writing a script that needs to take advantage of a Java daemon via

  • 0

I’m writing a script that needs to take advantage of a Java daemon via the local dbus of the linux machines it will run on. This daemon in particular will return an array of tuples which I want so that I can parse through/use the information in later in my code. I want this code to take this value from multiple machines at once, but the problem is the only way I see to really take return/exit values from a terminal which I am ssh’ed into is by parsing stdout’s output. I don’t want to do this, I’d much prefer to get the actual variable. Right now I have this:

import os
message = "import dbus, sys\nbus=dbus.SystemBus()\nremote_object=bus.get_object('daemon.location', '/daemon')\ncontroller=dbus.Interface(remote_object, 'daemon.path')\nsys.exit(controller.getValue())"
x = os.system('echo \-e "%s" \| ssh %s python' %(message, ip))

In this example when I run “controller.getValue()” it returns an array of tuples. I’m trying to figure out a way to get that array. When using something like popen it pipes the output in stdout into a file and returns it to you, that way you get a string equivalent of the array. What I’m trying to figure out is how to get the actual array. As if to pass the variable returned when exiting the ssh tty into my code. Any ideas?

  • 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-05-26T03:50:50+00:00Added an answer on May 26, 2026 at 3:50 am

    You can’t avoid serialization if there is no shared memory. There are only bytes on the wire.
    You could use a library that hides it from you e.g., with execnet module:

    #!/usr/bin/env python
    import execnet
    
    gw = execnet.makegateway("ssh=user@host")
    channel = gw.remote_exec("""
    import dbus, sys
    
    bus = dbus.SystemBus()
    remote_object = bus.get_object('daemon.location', '/daemon')
    controller = dbus.Interface(remote_object, 'daemon.path')
    
    channel.send(controller.getValue())
    """)
    tuple_ = channel.receive()
    print tuple_
    print tuple_[0]
    

    But it easy to parse simple tuple values yourself using ast.literal_eval() from stdlib:

    #fabfile.py
    import ast
    from fabric.api import run
    
    def getcontroller():
        """Return controller value."""
        cmd = """
    import dbus, sys
    
    bus = dbus.SystemBus()
    remote_object = bus.get_object('daemon.location', '/daemon')
    controller = dbus.Interface(remote_object, 'daemon.path')
    
    print repr(controller.getValue())
    """ #NOTE: you must escape all quotation marks
        output = run('python -c "%s"' % cmd)
        tuple_ = ast.literal_eval(output)
        print tuple_[0]
    

    Example: $ fab getcontroller -H user@host

    Here I’ve used fabric to run the command on remote host.

    You could use JSON as a serialization format if the other end doesn’t produce Python literals:

    >>> import json
    >>> t = (1, "a")
    >>> json.dumps(t)
    '[1, "a"]'
    >>> json.loads(_)
    [1, u'a']
    >>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am writing an app with both english and french support. The app requests
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.