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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:34:33+00:00 2026-05-22T16:34:33+00:00

I have an application that takes input, either from the terminal directly or I

  • 0

I have an application that takes input, either from the terminal directly or I can use a pipe to pass the output of another program into the stdin of this one. What I am trying to do is use python to generate the output so it’s formatted correctly and pass that to the stdin of this program all from the same script. Here is the code:

#!/usr/bin/python
import os 
import subprocess
import plistlib
import sys

def appScan():
    os.system("system_profiler -xml SPApplicationsDataType > apps.xml")
    appList = plistlib.readPlist("apps.xml")
    sys.stdout.write( "Mac_App_List\n"
    "Delimiters=\"^\"\n"
    "string50 string50\n"
    "Name^Version\n")
    appDict = appList[0]['_items']
    for x in appDict:
        if 'version' in x:
           print x['_name'] + "^" + x['version'] + "^"
        else:
           print x['_name'] + "^" + "no version found" + "^"
proc = subprocess.Popen(["/opt/altiris/notification/inventory/lib/helpers/aex-     sendcustominv","-t","-"], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
proc.communicate(input=appScan())

For some reason this subprocess I am calling doesn’t like what is coming into stdin. However if I remove the subprocess items and just have the script print to stdout and then call the script from the terminal (python appScan.py | aex-sendcustominv), aex-sendcustominv is able to accept the input just fine. Is there any way to take a functions output in python and send it to the stdin of an subprocess?

  • 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-22T16:34:33+00:00Added an answer on May 22, 2026 at 4:34 pm

    The problem is that appScan() only prints to stdout; appScan() returns None, so proc.communicate(input=appScan()) is equivalent to proc.communicate(input=None). You need appScan to return a string.

    Try this (not tested):

    def appScan():
        os.system("system_profiler -xml SPApplicationsDataType > apps.xml")
        appList = plistlib.readPlist("apps.xml")
        output_str = 'Delimiters="^"\nstring50 string50\nName^Version\n'
        appDict = appList[0]['_items']
        for x in appDict:
            if 'version' in x:
               output_str = output_str + x['_name'] + "^" + x['version'] + "^"
            else:
               output_str = output_str + x['_name'] + "^" + "no version found" + "^"
        return output_str
    
    proc = subprocess.Popen(["/opt/altiris/notification/inventory/lib/helpers/aex-     sendcustominv","-t","-"], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    proc.communicate(input=appScan())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that takes some input and generates configuration files as output.
If I have a 3 layer web forms application that takes user input, I
I have a custom routing application that takes information for a route from google
I have an ASP.NET web application that takes user input across several forms. Sort
Hello I have a Java application that takes an input number of operations to
I have an application that takes the quality results for a manufacturing process and
I have an application that takes a couple of seconds to run. Is it
I have an application with a REST style interface that takes XML documents via
I have a Java application that's very String-heavy - it takes a feed of
I have a web application that needs to take a file upload from 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.