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

  • Home
  • SEARCH
  • 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 8223173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:35:30+00:00 2026-06-07T14:35:30+00:00

I am in the process of writing a testing script that will simply run

  • 0

I am in the process of writing a testing script that will simply run an *.EXE file with a few arguments, and then output the result to a file. I have one *.sh testing script that correctly runs the tests (but requires manual updating for more tests). The lines in this script look like this:

blah.exe arg1 arg2 arg3 > ../test/arg4/arg4.out

I have written a python script to automatically generate the arguments based on a few simple python modules (it’s pretty rough right now):

import os
import subprocess

for test_dir in os.listdir():
    if not os.path.isdir(test_dir):
        continue
    # load a few variables from the ./test_dir/test_dir.py module
    test_module = getattr(__import__(test_dir, fromlist=[test_dir]), test_dir)

    # These arguments are relative paths, fix the paths
    arg1 = os.path.join(test_dir, test_module.ARG1)
    arg2 = os.path.join(test_dir, test_module.ARG2)
    arg3 = os.path.join(test_dir, test_module.ARG3)

    proc = subprocess.Popen(["../bin/blah.exe", arg1, arg2, arg3], stdout=subprocess.PIPE)

    stdout_txt = proc.stdout.read().decode("utf-8")

    with open(os.path.join(test_dir, test_dir + '.out'), 'w') as f:
        f.write(stdout_txt)

I have opened the files to compare and while the script is working, I ran across a problem. The first (shell) solution outputs correct line-endings. The second (python) solution outputs lines ending with CR CR LF. This looks correct in Notepad, but in Notepad++, every other line appears to be blank:

These lines should have no empty lines between them

Why is the output from python giving improper line endings?

How can I correct the line endings? (change CR CR LF to CR LF without having to write another script)

  • 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-07T14:35:32+00:00Added an answer on June 7, 2026 at 2:35 pm

    Try using the universal_newlines=True argument to Popen (see http://docs.python.org/library/subprocess.html#popen-constructor).

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

Sidebar

Related Questions

I'm writing a rather large script that will have to process a lot of
I am in the process of writing a Ruby script/app that helps me compiling
I'm writing a wrapper that forks an execv() process. Output from the child is
Im in the process of writing a python script to act as a glue
I'm in the process of writing a small text-editor that is supposed to have
I am in the process of writing a small WordPress data sync plugin that
I am writing a C# class that reads a file and encrypts using Rijndael
What are the current rules for writing python code that will pass cleanly through
I am in the process of writing an application that communicates with several devices
WHAT I'M DOING: I'm writing a C# application which will help employees process emails.

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.