1<html lang="en"> 2<head> 3<title>Input/Output - Debugging with GDB</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Debugging with GDB"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Running.html#Running" title="Running"> 9<link rel="prev" href="Working-Directory.html#Working-Directory" title="Working Directory"> 10<link rel="next" href="Attach.html#Attach" title="Attach"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13Copyright (C) 1988-2013 Free Software Foundation, Inc. 14 15Permission is granted to copy, distribute and/or modify this document 16under the terms of the GNU Free Documentation License, Version 1.3 or 17any later version published by the Free Software Foundation; with the 18Invariant Sections being ``Free Software'' and ``Free Software Needs 19Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' 20and with the Back-Cover Texts as in (a) below. 21 22(a) The FSF's Back-Cover Text is: ``You are free to copy and modify 23this GNU Manual. Buying copies from GNU Press supports the FSF in 24developing GNU and promoting software freedom.'' 25--> 26<meta http-equiv="Content-Style-Type" content="text/css"> 27<style type="text/css"><!-- 28 pre.display { font-family:inherit } 29 pre.format { font-family:inherit } 30 pre.smalldisplay { font-family:inherit; font-size:smaller } 31 pre.smallformat { font-family:inherit; font-size:smaller } 32 pre.smallexample { font-size:smaller } 33 pre.smalllisp { font-size:smaller } 34 span.sc { font-variant:small-caps } 35 span.roman { font-family:serif; font-weight:normal; } 36 span.sansserif { font-family:sans-serif; font-weight:normal; } 37--></style> 38<link rel="stylesheet" type="text/css" href="../cs.css"> 39</head> 40<body> 41<div class="node"> 42<a name="Input%2fOutput"></a> 43<a name="Input_002fOutput"></a> 44<p> 45Next: <a rel="next" accesskey="n" href="Attach.html#Attach">Attach</a>, 46Previous: <a rel="previous" accesskey="p" href="Working-Directory.html#Working-Directory">Working Directory</a>, 47Up: <a rel="up" accesskey="u" href="Running.html#Running">Running</a> 48<hr> 49</div> 50 51<h3 class="section">4.6 Your Program's Input and Output</h3> 52 53<p><a name="index-redirection-131"></a><a name="index-i_002fo-132"></a><a name="index-terminal-133"></a>By default, the program you run under <span class="sc">gdb</span> does input and output to 54the same terminal that <span class="sc">gdb</span> uses. <span class="sc">gdb</span> switches the terminal 55to its own terminal modes to interact with you, but it records the terminal 56modes your program was using and switches back to them when you continue 57running your program. 58 59 60<a name="index-info-terminal-134"></a> 61<dl><dt><code>info terminal</code><dd>Displays information recorded by <span class="sc">gdb</span> about the terminal modes your 62program is using. 63</dl> 64 65 <p>You can redirect your program's input and/or output using shell 66redirection with the <code>run</code> command. For example, 67 68<pre class="smallexample"> run > outfile 69</pre> 70 <p class="noindent">starts your program, diverting its output to the file <samp><span class="file">outfile</span></samp>. 71 72 <p><a name="index-tty-135"></a><a name="index-controlling-terminal-136"></a>Another way to specify where your program should do input and output is 73with the <code>tty</code> command. This command accepts a file name as 74argument, and causes this file to be the default for future <code>run</code> 75commands. It also resets the controlling terminal for the child 76process, for future <code>run</code> commands. For example, 77 78<pre class="smallexample"> tty /dev/ttyb 79</pre> 80 <p class="noindent">directs that processes started with subsequent <code>run</code> commands 81default to do input and output on the terminal <samp><span class="file">/dev/ttyb</span></samp> and have 82that as their controlling terminal. 83 84 <p>An explicit redirection in <code>run</code> overrides the <code>tty</code> command's 85effect on the input/output device, but not its effect on the controlling 86terminal. 87 88 <p>When you use the <code>tty</code> command or redirect input in the <code>run</code> 89command, only the input <em>for your program</em> is affected. The input 90for <span class="sc">gdb</span> still comes from your terminal. <code>tty</code> is an alias 91for <code>set inferior-tty</code>. 92 93 <p><a name="index-inferior-tty-137"></a><a name="index-set-inferior-controlling-terminal-138"></a>You can use the <code>show inferior-tty</code> command to tell <span class="sc">gdb</span> to 94display the name of the terminal that will be used for future runs of your 95program. 96 97 <dl> 98<dt><code>set inferior-tty /dev/ttyb</code><dd><a name="index-set-inferior_002dtty-139"></a>Set the tty for the program being debugged to /dev/ttyb. 99 100 <br><dt><code>show inferior-tty</code><dd><a name="index-show-inferior_002dtty-140"></a>Show the current tty for the program being debugged. 101</dl> 102 103 </body></html> 104 105