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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:46:01+00:00 2026-06-10T19:46:01+00:00

I have a pile of batch files that do something like this with program

  • 0

I have a pile of batch files that do something like this with program A:

A > log.txt ; grep 'result:' log.txt > result.txt || raise_hell.sh

What I’m trying to do is modify A so that it’ll print a bunch of intermediate results as it goes. However, it’s not as easy as you might think because A does the following:

  • calls _freopen(“somefile”,”w”,stdout), and then
  • calls printf (and variants thereof) in a million places and expects the output to end up in somefile.

It’s not really practical for me to change every single printf in the project. Nor is it practical to change every batch file, so I don’t really know where my output’s being redirected to.

Ideally, I’d like to have some way to get to the “original value” of stdout, and just write there. But how? I can even replace the call to freopen with something else so long as the output still ends up where it should.

In other words I’d like for printf to end up in a file, and to have some other way to print stuff to standard out.

I’ve tried a number of things, in part based on answers to variations of this question. However, none of those work because they still all end up writing to somefile. Help would be welcome.

edit: Just to be clear, this is on Windows, using Visual Studio 2010.

  • 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-10T19:46:02+00:00Added an answer on June 10, 2026 at 7:46 pm

    OK, I’m not a Windows guy, but just as an answer to the specific question: how to mess w/stdout. In UNIX we’d use dup/dup2, which according to:

    http://www.suacommunity.com/dictionary/dup-entry.php

    is only slightly different in windows. The basic idea in UNIX is that stdout is file descriptor 1…changing what is open there is equivalent to redirecting it. Using dup, you can make a copy of it first, in case you want to put it back.

    In general, though, I’d use stderr for progress messages…that is why it exists.

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

Sidebar

Related Questions

I have a pile of dbfs that I am trying to churn into xls.
I have an issue where I have something like this: class Thing(models.Model): def can_vote(self,
Let's see if I can describe this properly... I have an abstract class that
We have a pile of old databases in archives that have a column named
this is my first question :) I have one pile file, and I have
New to spring, we have a whole pile of validators that generate java warnings,
I feel like this is a pile of you know what I mean. It
I have a git repository that's used only to hold graphics and sound files
Say that I have 4 numpy arrays [1,2,3] [2,3,1] [3,2,1] [1,3,2] In this case,
For instance, I have a document that has a pile of control codes that

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.