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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:53:35+00:00 2026-05-27T02:53:35+00:00

How do send an input to GDB whenever scanf is triggered using external program??

  • 0

How do send an input to GDB whenever scanf is triggered using external program??

c file:

#include<stdio.h>

void main()
{
    int x;
    int y;
    printf("input x: ");
    scanf("%d",&x);
    printf("input y: ");
    scanf("%d",&y);

}

Java external program:

public class Debugger extends Thread{

        public void run(){
        Process p = null;
        try {
        p = Runtime.getRuntime().exec("gdb a.out --interpreter=console");
       new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
       new Thread(new SyncPipe(p.getInputStream(), System.out)).start();
        PrintWriter stdin = new PrintWriter(p.getOutputStream());

        stdin.flush();
        stdin.println("break main");
        stdin.flush();
        stdin.println("run");
        stdin.flush();
        stdin.println("s");
        stdin.flush();
        stdin.println("45");
        stdin.flush();

       // stdin.close();


        } catch (Exception e) {
            e.printStackTrace();
        }
        }
    }

class SyncPipe implements Runnable
{

    public SyncPipe(InputStream istrm, OutputStream ostrm) {
      istrm_ = istrm;
      ostrm_ = ostrm;

  }

  public void run() {

      try
      {   
          int length;
           byte[] buffer = new byte[1024];

          for ( length = 0; (length = istrm_.read(buffer)) != -1; ){

              ostrm_.write(buffer, 0, length);
          } 

      }
      catch (Exception e)
      {
          e.printStackTrace();
      }


  }


  private final OutputStream ostrm_;
  private final InputStream istrm_;
}

GDB output from external program:

GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/charmae/workspace/AVT/a.out...done.
(gdb) Breakpoint 1 at 0x804843d: file file4.c, line 7.
(gdb) Starting program: /home/charmae/workspace/AVT/a.out 

Breakpoint 1, main () at file4.c:7
7       printf("input of x: ");
(gdb) 8     scanf("%d",&x);
(gdb) Undefined command: "45".  Try "help".
(gdb) 
  • 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-27T02:53:35+00:00Added an answer on May 27, 2026 at 2:53 am

    You could redirect input like in the shell

    (gdb) run < input.txt
    

    Alternatively, you can run the program in another terminal and connect to it by PID:

    gdb --pid $(pgrep myprogram.name)
    

    Lastly, you could do similar hacks using direct calls to dup2/dup3 (but I don’t think you need to do that, it won’t be userfriendly)

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

Sidebar

Related Questions

I'm wondering how I can hook up an input type=file to send a picture
How can I do this? Here's what I have: function send(input):void{ // input.text =
How do you send keyboard input to a program? That is, under a Linux
Is there such a program that can open a little input box and send
How can I send keyboard input messages to either the currently selected window or
i'm trying to send fake keyboard input to an application that's running in a
I have input fields, which I process with AJAX and send it on another
i send ajax requests with jquery, and i have a function: $('input').ajaxSuccess(function(e, xhr, settings)
How can you disable the send -button if there is one or more input
I send email through Outlook using VB.Net 2005; this is working fine. At 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.