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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:51:02+00:00 2026-05-26T00:51:02+00:00

I need to test some programs by running them and verifying the output, and

  • 0

I need to test some programs by running them and verifying the output, and the entire test data shall be copied into a report. By entire test data, I mean both the output (stdout) of the program and the input (stdin) to the program need to be in the report. For example, let’s say I run python to do some calculations. A simple session may look like this:

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.sqrt(2)
1.4142135623730951
>>> math.log(2)
0.6931471805599453
>>> 2 ** 32
4294967296
>>> 

Here, I have my inputs and the outputs (the prompts and results of my calculations).

My question is, given a program and possibly a file containing the stdin for that program, how can I get all textual data of the program’s run as though I ran it interactively, like the above python session? In other words, how can I get the above text from the python session given the python program and a text file (for input) containing:

import math
math.sqrt(2)
math.log(2)
2 ** 32

I could run the program in a shell and copy the output, but it doesn’t seem like a clean, systematic way of doing it. Instead, I’m thinking writing another program that takes the given program as an argument as well as a filename (from which to read input). This second program would read from the given file, fork the given program, forward the text from the file to the given program (by means of a pipe), and read the output of the given program (also by a pipe). That way this intermediary program can read both the input and the output, and can write them to another file.

The only problem I foresee is that due to stream buffers and what not, the placement of the inputs and outputs in the final output file will be off, and I won’t get the intended output. So, is my logic correct, and if so, will I be able to get the output the way I want it? Is there a simpler way to do this, e.g., a program already exists that does this?

Sorry for the long explanation. Thanks for your responses.

  • 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-26T00:51:02+00:00Added an answer on May 26, 2026 at 12:51 am

    Try the script command. By default it only captures output, but it can also capture input as well.

    script -akq capture.log my-fun-little-command and its args
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to test a program that first preprocesses some data and then computes
While developing products, we often need to create proprietary tools to test some of
I have some code in my error handler I need to test against a
I need some like this: module One def test; puts 'Test One'; end end
I need some advice as to how I easily can separate test runs for
I need to copy some records from our SQLServer 2005 test server to our
I'm running some JUnit tests on my applications. Every test has a for loop
I'm using Python 3.2 and the configparser module, and running into some problems. I
I frequently need to debug .NET binaries on test machines (by test-machine, I mean
I need to find a way to automate some UI testing of .NET programs

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.