05-29-2017
If you want to script interaction with a program expecting human input, bash and most other shells are very bad at that. Pipes are poor substitutes for the interactive terminal the program is obviously expecting, they tend to deadlock with each process waiting for the other and no way to notify each other of said fact.
If your interaction is any more complicated than typing one number and hitting enter, you might look into the expect language, which is designed for these sort of problems. It will allocate a PTY which allows it to control the program it's communicating with asynchronously without all the piping and redirection.
Last edited by Corona688; 05-29-2017 at 03:15 PM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Working in a bash environment, in the following example, how do I direct the error message that putting in an invalid flag (-j for example) would normally produce to dev/null?
while getopts "abcd" opt
do
case "$opt" in
i) a etc ;;
r) b etc ;;
f) c etc ;;
v) d... (7 Replies)
Discussion started by: Sniper Pixie
7 Replies
2. Shell Programming and Scripting
can you redirect STDIN with command arguments?
I have tried this approach:
# ./script -option <argument1> <argument2> 0<$2
# $2: ambiguous redirect
Is this possible? (4 Replies)
Discussion started by: prkfriryce
4 Replies
3. Shell Programming and Scripting
Consider:
#!/bin/sh
#this is a shell script in sh (bourne)
grep missingfile 2>errout.txt
It works from the command line, but keeps producing errors from the script. So how do I redirect in a bash shell...or bourne? (3 Replies)
Discussion started by: lumix
3 Replies
4. Programming
For windows was pretty simple to redirect the std in a and out of a
child process for "cmd.exe " command prompt terminal to a socket using connected pipes passed to a new process in the STARTUPINFO structure.
BOOL b = ::CreatePipe((LPHANDLE)h_stdInRead,(LPHANDLE)hsdtInWriteTmp, &SecAttrib,... (1 Reply)
Discussion started by: gyula
1 Replies
5. Shell Programming and Scripting
Hi:
I have the next script on ksh
#!/usr/bin/ksh
cd $FUENTES
qdesign <<-!
\$/opt/cognos/ph843e/bin/qtp <<-!
\$/opt/cognos/ph843e/bin/quiz <<-!
!
!
!
This script is very simple, i want to nest three process quiz into qtp, and this into qdesign.
When I run it , i receive the... (5 Replies)
Discussion started by: ct2marer
5 Replies
6. UNIX for Advanced & Expert Users
Hi:
I have the next script on ksh
#!/usr/bin/ksh
cd $FUENTES
qdesign <<-!
\$/opt/cognos/ph843e/bin/qtp <<-!
\$/opt/cognos/ph843e/bin/quiz <<-!
!
!
!
This script is very simple, i want to nest three process quiz into qtp, and this into qdesign.
When I run it , i receive the next... (2 Replies)
Discussion started by: ct2marer
2 Replies
7. Shell Programming and Scripting
I am unable to use STDIn redirection with < (commands)
When I do the following, both approaches work and give the same results:
1.
$ printf "aaa\nbbb\n" > file1
$ printf "111\n222\n" > file2
$ cat file1 file2
aaa
bbb
111
2222.
$ cat <(printf "aaa\nbbb\n") <(printf "111\n222\n")
aaa... (8 Replies)
Discussion started by: metaltree
8 Replies
8. Shell Programming and Scripting
Looking for the proper way to bring a string into the stdin. I have a string that I would like to grep and awk. Each have to be run separately, not piped together. So far, the only way I could figure out how is to echo the string and pipe it:
echo 'This is my string' | grep my (3 Replies)
Discussion started by: Panman82
3 Replies
9. UNIX for Advanced & Expert Users
I want to differentiate the STDOUT and STDERR messages in my terminal .
If a script or command is printing a message in terminal I want to differentiate by colors,
Is it possible ?
Example:
$date
Wed Jul 27 12:36:50 IST 2011
$datee
bash: datee: command not found
$alias ls
alias... (2 Replies)
Discussion started by: ungalnanban
2 Replies
10. Shell Programming and Scripting
Hi, I'm running a program (Python) whose output I would like to redirect to a log. But the program calls a library (that I cannot change), which outputs all sorts of useless information.
I would like to redirect all output from my Python program into this log, except output that matches the... (7 Replies)
Discussion started by: rswindle
7 Replies
PTY(4) Kernel Interfaces Manual PTY(4)
NAME
pty - pseudo terminal driver
SYNOPSIS
/sys/conf/SYSTEM:
NPTY ptys # pseudo-terminals, in groups of 8
DESCRIPTION
The pty driver provides support for a device-pair termed a pseudo terminal. A pseudo terminal is a pair of character devices, a master
device and a slave device. The slave device provides processes an interface identical to that described in tty(4). However, whereas all
other devices which provide the interface described in tty(4) have a hardware device of some sort behind them, the slave device has,
instead, another process manipulating it through the master half of the pseudo terminal. That is, anything written on the master device is
given to the slave device as input and anything written on the slave device is presented as input on the master device.
In configuring, ptys specifies the number of pseudo terminal pairs are configured.
The following ioctl calls apply only to pseudo terminals:
TIOCSTOP
Stops output to a terminal (e.g. like typing ^S). Takes no parameter.
TIOCSTART
Restarts output (stopped by TIOCSTOP or by typing ^S). Takes no parameter.
TIOCPKT
Enable/disable packet mode. Packet mode is enabled by specifying (by reference) a nonzero parameter and disabled by specifying (by
reference) a zero parameter. When applied to the master side of a pseudo terminal, each subsequent read from the terminal will
return data written on the slave part of the pseudo terminal preceded by a zero byte (symbolically defined as TIOCPKT_DATA), or a
single byte reflecting control status information. In the latter case, the byte is an inclusive-or of zero or more of the bits:
TIOCPKT_FLUSHREAD
whenever the read queue for the terminal is flushed.
TIOCPKT_FLUSHWRITE
whenever the write queue for the terminal is flushed.
TIOCPKT_STOP
whenever output to the terminal is stopped a la ^S.
TIOCPKT_START
whenever output to the terminal is restarted.
TIOCPKT_DOSTOP
whenever t_stopc is ^S and t_startc is ^Q.
TIOCPKT_NOSTOP
whenever the start and stop characters are not ^S/^Q.
While this mode is in use, the presence of control status information to be read from the master side may be detected by a select
for exceptional conditions.
This mode is used by rlogin(1C) and rlogind(8C) to implement a remote-echoed, locally ^S/^Q flow-controlled remote login with proper
back-flushing of output; it can be used by other similar programs.
TIOCUCNTL
Enable/disable a mode that allows a small number of simple user ioctl commands to be passed through the pseudo-terminal, using a
protocol similar to that of TIOCPKT. The TIOCUCNTL and TIOCPKT modes are mutually exclusive. This mode is enabled from the master
side of a pseudo terminal by specifying (by reference) a nonzero parameter and disabled by specifying (by reference) a zero parame-
ter. Each subsequent read from the master side will return data written on the slave part of the pseudo terminal preceded by a zero
byte, or a single byte reflecting a user control operation on the slave side. A user control command consists of a special ioctl
operation with no data; the command is given as UIOCCMD(n), where n is a number in the range 1-255. The operation value n will be
received as a single byte on the next read from the master side. The ioctl UIOCCMD(0) is a no-op that may be used to probe for the
existence of this facility. As with TIOCPKT mode, command operations may be detected with a select for exceptional conditions.
TIOCREMOTE
A mode for the master half of a pseudo terminal, independent of TIOCPKT. This mode causes input to the pseudo terminal to be flow
controlled and not input edited (regardless of the terminal mode). Each write to the control terminal produces a record boundary
for the process reading the terminal. In normal usage, a write of data is like the data typed as a line on the terminal; a write of
0 bytes is like typing an end-of-file character. TIOCREMOTE can be used when doing remote line editing in a window manager, or
whenever flow controlled input is required.
FILES
/dev/pty[p-r][0-9a-f] master pseudo terminals
/dev/tty[p-r][0-9a-f] slave pseudo terminals
DIAGNOSTICS
None.
4.2 Berkeley Distribution May 19, 1986 PTY(4)