Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently trying to write a scan port result to a text file

Here is the command I tried to use:

nc -vv -z localhost 1-80 > file.txt

This doesn't work (that is, the error messages from nc don't end up in file.txt), but when I type: nc -vv -z localhost 80 > file.txt It works.

I already know that there is an output but I can't write that in a file.

share|improve this question
    
I heard that netcat output was stderr I tried '2>' too and even '2>&1' but it's still doesn't work – Lapinou Mar 29 '15 at 16:16
    
What do you mean by "This doesn't work"? Do you mean that you cannot get the error messages from nc into file.txt? – roaima Mar 29 '15 at 16:17
    
It's doesn't write the output in a .txt file – Lapinou Mar 29 '15 at 16:17
up vote 3 down vote accepted

You need to direct both stderr and stdout into the file:

nc -vv -z localhost 1-80 > file.txt 2>&1
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.