formateu
formateu

Reputation: 167

Bash, cygwin, run command with user input (disable process switch)

I want to run command in console and insert all user data needed.

#!/bin/bash
program < data &

My code works, but after less than second program disappears (only blinks). How can I run program, pass data from file and stay in that program(I have no need to continue bash script after app launching.)

Upvotes: 0

Views: 260

Answers (1)

John Bollinger
John Bollinger

Reputation: 180361

Inasmuch as the program you are launching reads data from its standard input, it is reasonable to suppose that when you say that you want to "stay in that program" you mean that you want to be able to give it further input interactively. Moreover, I suppose that the program disappears / blinks either because it is disconnected from the terminal (by operation of the & operator) or because it terminates when it detects end-of-file on its standard input.

If the objective is simply to prepend some canned input before the interactive input, then you should be able to achieve that by piping input from cat:

cat data - | program

The - argument to cat designates the standard input. cat first reads file data and writes it to standard out, then it forwards data from its standard input to its standard output. All of that output is fed to program's standard input. There is no need to exec, and do not put either command into the background, as that disconnects it from the terminal (from which cat is obtaining input and to which program is, presumably, writing output).

Upvotes: 1

Related Questions