I want to print the actual remaining time and this in the way in one line on the screen. So I print the persistend part of the text before the while-loop and only overwrite the old number characters of the text within the while. There is time.sleep() in the space of the while loop. But this does not matter. It does not print. Not until the while-loop was passed.  I work with Windows 7 by the way.  I tried to change the output stream to a file to figure out if cmd is too slow. I tailed the file with notepad++. The same happening. It seems to me a newline is important to print.      import sys     temp = sys.stdout     sys.sdtout = open('testfile.txt', 'w')     # my code &lt;---*     sys.stdout.close()     sys.stdout = temp     # my similiar code to demonstrate *---&gt; i = 5 m = len(str(i)) print('Remaining time in seconds: {}'.format(' ' * m), end='') while i:     m = len(str(i+1))     st = '{}{}'.format('\b' * m, i)     print(st, end='')     time.sleep(1)     i -= 1 print('\b0')
9533
How do I force Python's print function to output to the screen?
82090
int i = 4; string text = "Player "; cout &lt;&lt; (text + i);   I'd like it to print Player 4.  The above is obviously wrong but it shows what I'm trying to do here. Is there an easy way to do this or do I have to start adding new includes?
123988
I have a program which produces useful information on stdout but also reads from stdin. I want to redirect its standard output to a file without providing anything on standard input. So far, so good: I can do:  program &gt; output   and don't do anything in the tty.  However, the problem is I want to do this in the background. If I do:  program &gt; output &amp;   the program will get suspended ("suspended (tty input)").  If I do:  program &lt; /dev/null &gt; output &amp;   the program terminates immediately because it reaches EOF.  It seems that what I need is to pipe into program something which does not do anything for an indefinite amount of time and does not read stdin. The following approaches work:  while true; do sleep 100; done | program &gt; output &amp; mkfifo fifo &amp;&amp; cat fifo | program &gt; output &amp; tail -f /dev/null | program &gt; output &amp;   However, this is all very ugly. There has to be an elegant way, using standard Unix utilities, to "do nothing, indefinitely" (to paraphrase man true). How could I achieve this? (My main criteria for elegance here: no temporary files; no busy-waiting or periodic wakeups; no exotic utilities; as short as possible.)
33769
I haven't had the chance to take any serious low-level programming courses in school. (I know I really should get going on learning the "behind-the-scenes" to be a better programmer.) I appreciate the conveniences of Java, including the ability to stick anything into a System.out.print statement. However, is there any reason why you would want to use System.out.printf instead?   Also, should I avoid print calls like this in "real applications"?  It's probably better to  to print messages to the client's display using some kind of UI function, right?
61066
I have a file which includes comments: foo bar stuff #Do not show this... morestuff evenmorestuff#Or this  I want to print the file without including any of the comments: foo bar stuff morestuff evenmorestuff  There are a lot of applications where this would be helpful.  What is a good way to do it?
116620
What is the most elegant way to solve this:   open a file for reading, but only if it is not already opened for writing open a file for writing, but only if it is not already opened for reading or writing   The built-in functions work like this  &gt;&gt;&gt; path = r"c:\scr.txt" &gt;&gt;&gt; file1 = open(path, "w") &gt;&gt;&gt; print file1 &lt;open file 'c:\scr.txt', mode 'w' at 0x019F88D8&gt; &gt;&gt;&gt; file2 = open(path, "w") &gt;&gt;&gt; print file2 &lt;open file 'c:\scr.txt', mode 'w' at 0x02332188&gt; &gt;&gt;&gt; file1.write("111") &gt;&gt;&gt; file2.write("222") &gt;&gt;&gt; file1.close()   scr.txt now contains '111'.  &gt;&gt;&gt; file2.close()   scr.txt was overwritten and now contains '222' (on Windows, Python 2.4).  The solution should work inside the same process (like in the example above) as well as when another process has opened the file. It is preferred, if a crashing program will not keep the lock open.
44061
When running 'screen ls' the screen stops with the text [screen is terminating]. I would like screen to keep the session alive and reattach to it to see the output of ls.  Of course the real thing is that I don't run screen ls, but rather a screen fsck ..., so I would like to ensure that the screen is not terminating when this command is finished.  I would love to have an answer that is useful for an already existing running screen session, so some interactive keys like C-a ... or C-a : (Enter command line mode)
15709
I want to print two files in two columns -- first file on the left side and second on the right side. paste doesn't do the job, because it can only insert a character as delimiter, so if first file lines have different length output will be twisted: $ cat file1 looooooooong line line $ cat file2 hello world $ paste file1 file2 looooooooong line   hello line    world  If it was a command to add trailing spaces like fmt --add-spaces --width 50 the problem would be solved: $ paste &lt;(fmt --add-spaces --width 50 file1) file2 looooooooong line                                 hello line                                              world  But I don't know a simple way to do this. So how to merge and print several files horizontally without twisting? Actually, I just want to look at them simultaneously.  UPD: command to add trailing spaces does exist (for example, xargs -d '\n' printf '%-50s\n') But solution like $ paste &lt;(add-trailing-spaces file1) file2  does not work as expected when file1 has fewer lines than file2.
105543
From man watch:     Non-printing characters are stripped   from program output.  Use "cat -v" as   part of the command pipeline if you   want to see them.   So how do I use cat -v if I want to see the colored output from:  watch ls -al --color
107478
If I time a process using the time command, I get output for 'real', 'user', and 'sys'.  My understanding from  is that 'real' is wall time, whereas 'user' and 'sys' are process time.  Does this imply that 'user' and 'sys' will be unaffected by other processes? In other words, if the computer is under heavy load or light load from other processes, it may take more time on the wall clock ('real') to finish my process. But my process may have only required 5 seconds of running time, even though it was spread out over 20 seconds of real-world time.  Am I guaranteed that I'll be told '5 seconds user time' regardless of whatever else the system is doing?
99936
In Perl, I can type:  $|++;   and anything printed to STDOUT will be automatically fflush()ed.  Is there an equivalent in C? In other words, is there some way I can tell stdio to automatically fflush stdout after every printf(), the way it automatically flushes stderr?
12888
I'm trying to print types like off_t and size_t.  What is the correct placeholder for printf() that is portable?  Or is there a completely different way to print those variables?
23438
Okay. If I wanted to redirect the output of a program to a file, I'd do something like this  prog &gt; file   If I wanted to redirect both stdout and stderr to that file, then I'd do  prog &gt; file 2&gt;&amp;1   This is all well and good if you want the output to go to the file. But what if you want the output to go to the file and yet still go to stdout/stderr? So, the output is saved in the file, but you can still see it on the console as the program is running. Is there a way to do that? And if so, how?
8955
I'm using this code to get standard output from an external program:  &gt;&gt;&gt; from subprocess import * &gt;&gt;&gt; command_stdout = Popen(['ls', '-l'], stdout=PIPE).communicate()[0]   The communicate() method returns an array of bytes:  &gt;&gt;&gt; command_stdout b'total 0\n-rw-rw-r-- 1 thomas thomas 0 Mar  3 07:03 file1\n-rw-rw-r-- 1 thomas thomas 0 Mar  3 07:03 file2\n'   However, I'd like to work with the output as a normal Python string. So that I could print it like this:  &gt;&gt;&gt; print(command_stdout) -rw-rw-r-- 1 thomas thomas 0 Mar  3 07:03 file1 -rw-rw-r-- 1 thomas thomas 0 Mar  3 07:03 file2   I thought that's what the  method is for, but when I tried it, I got the same byte array again:  &gt;&gt;&gt; binascii.b2a_qp(command_stdout) b'total 0\n-rw-rw-r-- 1 thomas thomas 0 Mar  3 07:03 file1\n-rw-rw-r-- 1 thomas thomas 0 Mar  3 07:03 file2\n'   How do I convert the bytes value back to string? I mean, using the "batteries" instead of doing it manually. And I'd like it to be OK with Python&nbsp;3.
106050
Hi I'm pretty new to Stack Overflow so I hope that I'm doing this correctly and that someone out there has the answer I need.  I'm currently coding a program in Java with Eclipse IDE an my question is this:  I need a snippet of code that does the following  It's supposed to get a .TXT file containing text and from that .TXT file  count the number of rows and print it,  count the number of words and print it,  count the number of characters and print it. And finally make a list of the top 10 words used and print that.  Allt the printing is done to system outprintln  I'm pretty new to Java and am having some difficulties.  Anyone out there who can provide me with these lines of code or that knows where i can find them? I want to study the code provided that's how I learn best=)  Thanks to all   Didnt find the edit button sorry...  I Added this to my question:  Hehe it´s an assignment but not a homework assignment ok i see well i could provide what i've done so far, i think im pretty close but it´s not working for me. Is there anything i have missed?  // Class    Tip   import java.io.*; import java.util.*;  class Tip {     public static void main(String [] args) throws Exception     {          String root = System.getProperty("user.dir");            InputStream is = new FileInputStream( root + "\\tip.txt" );         Scanner scan = new Scanner( is );          String tempString = "";         int lines = 0;         int words = 0;         Vector&lt;Integer&gt; wordLength = new Vector&lt;Integer&gt;();         int avarageWordLength = 0;          while(scan.hasNextLine() == true)         {                 tempString = scan.nextLine();                 lines++;         }          is.close();          is = new FileInputStream( root );         scan = new Scanner( is );          while(scan.hasNext() == true)         {                 tempString = scan.next();                 wordLength.add(tempString.length());                 words++;         }          for(Integer i : wordLength)         {                 avarageWordLength += i;         }         avarageWordLength /= wordLength.size();           System.out.println("Lines : " + lines);         System.out.println("Words : " + words);         System.out.println("Words Avarage Length : " + avarageWordLength);          is.close();          } }
101118
I want to display text output on the console that is always displayed on a small screen on my Raspberry Pi.   The following code works for showing that text output:  cd /home/pi/python_test_scripts_linux &amp;&amp; sudo nice -n -20 /home/pi/python_test_scripts_linux/test_wrapper.py &gt; /dev/tty1   Now I want to capture the output in parallel with seeing it on the screen - I have tried 'tee' but that does not show text on the screen and also does not capture it to file:  cd /home/pi/python_test_scripts_linux &amp;&amp; sudo nice -n -20 /home/pi/python_test_scripts_linux/test_wrapper.py | tee /dev/tty1 /tmp/capture.txt   How can I redirect the output of my script to /dev/tty1 so I can see it on my screen but also capture the output to file?  UPDATE 1:  Per the answer below - I tried using 'script' - unfortunately it did not work:  script -c "cd /home/pi/python_test_scripts_linux &amp;&amp; sudo nice -n -20 /home/pi/python_test_scripts_linux/test_wrapper.py &gt; /dev/tty1" /home/pi/python_test_scripts_linux/report.html   UPDATE 2:  I also tried to 'tail' the output of the file that I redirected the output to into /dev/tty1, but it also did not work:  sudo tail -F /home/pi/python_test_scripts_linux/report.html &gt; /dev/tty1 &amp; cd /home/pi/python_test_scripts_linux &amp;&amp; sudo nice -n -20 /home/pi/python_test_scripts_linux/test_wrapper.py &gt; /home/pi/python_test_scripts_linux/report.html
35540
I have a file with many rows, and each row has a timestamp at the starting, like  [Thread-3] (21/09/12 06:17:38:672) logged message from code.....   So, I frequently check 2 things from this log file.   First few rows, that has the global conditions and start time is also given. Last few rows, that has the exit status with some other info.   Is there any quick handy single command that could let me display just the first and last few lines of a file?