Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Is it possible for an application to block data from coming from pipes, but still accepting from a normal user shell</p> </blockquote> <p>It can call <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/isatty.html" rel="nofollow"><code>isatty</code></a> which will tell it if input comes from a terminal or not.</p> <blockquote> <p>if that's the case, is there anything I can do to make it accept my pipe input</p> </blockquote> <p>There is a way, but you might not like it:</p> <ol> <li>Open a pseudoterminal using <code>posix_openpt</code> <code>grantpt</code> and <code>unlockpt</code>. You now have the "master" fd</li> <li>Fork a new process</li> <li>Call <code>setsid()</code> in the new process to kill its terminal association</li> <li>In the child call <code>ptsname</code> on the fd obtained in step 1</li> <li>Open the name obtained from <code>ptsname</code> and call <code>TIOCSTTY</code> on it - it becomes the controlling terminal</li> <li>Duplicate the descriptor obtained in step 5 into <code>STDIN_FILENO</code></li> <li>Exec your program</li> </ol> <p>You can probably adapt <a href="http://man7.org/tlpi/code/online/dist/pty/pty_fork.c.html" rel="nofollow">the function <code>ptyFork</code></a> from TLPI for this or <a href="http://www.apuebook.com/code3e.html" rel="nofollow">the function <code>pty_fork</code> from APUE</a>.</p> <p>At this point you can write into the master fd - as if it were a pipe - from your process and the child will think it comes from a terminal.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload