gansm / finalcut

A text-based widget toolkit
https://github.com/gansm/finalcut/wiki/First-steps#first-steps-with-the-final-cut-widget-toolkit
GNU Lesser General Public License v3.0
1k stars 52 forks source link

std::cout #47

Closed wimstockman closed 3 years ago

wimstockman commented 4 years ago

Hi, it's me again. Thanks again for resolving the std::cin problem. But now I have the following problem if I do : finalcutdemo > file.txt I don't see my finalcut window appear. if I close the stdout like with the stdinput I see my finalcut program. but I cannot get the output the be written to the file.txt. I should be able to reattach the stdoutput. Or to make only the finalcut windows appear to tty. Do you have an idea ?

kind regard, Wim Stockman

gansm commented 4 years ago

Hi Wim, I don't understand why you don't pass the filename of the output file to your program with a command argument?

For example ./finalcutdemo -o output.file

The ">" creates an I/O redirection that prevents that FINAL CUT works correctly with the terminal/tty. This prevents that core functions like the terminal detection works!

Here is a small example with a shell script:

$ cat is-tty.sh 
#!/bin/sh

if [ -t 1 ]
then
  echo "STDOUT is attached to TTY"
fi

if [ -p /dev/stdout ]
then
  echo "STDOUT is attached to a pipe"
fi

if [ ! -t 1 ] && [ ! -p /dev/stdout ]
then
  echo "STDOUT is attached to a redirection"
fi
$ ./is-tty.sh 
STDOUT is attached to TTY
$ ./is-tty.sh | cat >/dev/tty
STDOUT is attached to a pipe
$ ./is-tty.sh >file.txt ; cat file.txt 
STDOUT is attached to a redirection

I hope you see where the problem is?

This may not be the answer you had expected, but it makes no sense to work against the default behavior of the system.

wimstockman commented 4 years ago

Hi Markus,

Thanks for your answer. I found the solution: int stdoutBack = dup(1); close(1); int output = open("/dev/tty",O_RDWR); init(argc,argv,vector); // Here I start the finalcut program dup2(stdoutBack,1);

When I finish my little demo I will sent it to you so you can see why I needed it for :-)

Kind regards, Wim

gansm commented 3 years ago

Closed because of inactivity.