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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:27:25+00:00 2026-06-04T02:27:25+00:00

I’m using some pipe and fork to execute a command like cat file.tar.gz |

  • 0

I’m using some pipe and fork to execute a command like

cat file.tar.gz | myprogram -c “tar -zvt” -i “remoteMachineIp”

But if i do

myprogram -c “bash” -i “remoteMachineIp”

The bash is ok, but no tty.
Without the tty if i call the vim command it opens the vi messed.

How can i call the bash on execlp with the tty.

Code Example

if(cm->pid2==0){ //pipe and fork to send data to my execlp
close(cm->fout[0]);
dup2(cm->fout[1], 1);
execlp("bash", "bash", "-c", command.c_str(), NULL); // command is mycommand so is bash -c "bash"
}
else{
close(cm->fout[1]);
while((size=read(cm->fout[0], buffer, 2000)) > 0){
cm->message->send(buffer, size); //send the data to my program
}
//Close it and send the return code

The problem is the execlp returns the bash to me, but no tty
If i call ssh user@machine “bash” the bash comes with problem, but jut ssh user@machine its ok

How can i call the bash with the tty?

Thanks

  • 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-04T02:27:26+00:00Added an answer on June 4, 2026 at 2:27 am

    I guess that your concern is that the command you launch inherits stdin from its parent (myprogram) and its parent’s stdin is the pipe that accepts data from cat file.tar.gz. You would like to run a child that is forced to read data from the tty, not the inherited stdin pipe.

    You can open /dev/tty to get a reference to the tty. It will fail if there is no tty. For example:

    close(0);
    open("/dev/tty", O_RDWR);
    /* The file descriptor returned by open should be 0 */
    

    However, I notice that you redirect the child command’s stdout to a pipe to your program. If the command you are execing is interactive, this will not work. An interactive command needs to have both its input and its output connected to a tty. Launching an interactive command with its output connected to a pipe probably does not make any sense, regardless of whether you connect stdin to a tty.

    By the way: why do you use bash -c <command> instead of sh -c <command> in your execlp? This way you introduce an unnecessary dependency on bash where all you really need is the standard POSIX bourne shell sh. execing through sh -c is the standard way to launch a command through a shell. This is what’s done, for example, by system().

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

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.