Redirect output of "netstat -n"

  • Hello,


    I want to get the output of "netstat -n" into file for later checks.

    Neither a redirection by "netstat -n > output.txt" and "netstat -n 2> output.txt" nor a call of "CreateProcess()" in C++ program does it correctly.

    The problem is, the tool netstat delivers its output always on display shortly and closes the output after finished.

    Does anybody know a way, how to get the result into a textfile or memory in C++ program?

    Would be great, if someone could help me.

    Best ragards, Andy

  • Hello, test following on the cmd shell, it works : (I modify the "echo" sample from here Redirect )


    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello,


    oh thanks - that's working - but only for the root directory.

    When I want it to write to FFSDISK dirctory, it is not working.

    It's always written into the root directory, where some tool have no access.

    I have tried "> /FFSDISK/x.txt" - there I get the error: "Cannot open \ffsdisk\ffsdisk\x.txt as standard output."

    When I try "> /x.txt" in FFSDISK directory, it writes to root directory. It also don't work with backslash characters.

    Are there maybe access problems?

  • Hello, please check the following (if any issues you may use finally the copy command):

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • When I try your example, I get following results:


    netstat -n >> "/ffsdisk/exampleOutput.txt" in executed in root directory:

    -> Output is shown shorty on display and created file is empty.


    netstat -n >> "/ffsdisk/exampleOutput.txt" executed in /ffsdisk directory:

    -> Receive error message: "Cannot open \ffsdisk\ffsdisk\exampleOutput.txt as standard output."


    netstat -n >> "./exampleOutput.txt" executed in /ffsdisk directory:

    -> Output is shown shorty on display and created file is empty.


    netstat -n >> "./exampleOutput.txt" executed in root directory:

    -> Works.


    netstat -n >> "/exampleOutput.txt" executed in root directory:

    -> Works.


    Seems that I have to use the copy command...

    It works with a batch file, which changes dir to root, executes netstat and moves result file to ffsdisk directory.


    Don't know the difference to your example. Are you on the same hardware? I'm connected to a NetDCUA9 board (Kernel V3.8) by telnet.

  • Thanks for this information.

    Seems to be a "WCE6 bug". I test it under WEC2013 but I await same notation should work under WCE6 too!

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • I thought, I have Win EC7?

    In System Properties I can see:

    Microsoft Windows Embedded Compact Version 7.00 (Build 2882)


    After telnet login I see:

    Code
    1. Welcome to the Windows CE Telnet Service on FSIMX6
    2. Pocket CMD v 7.00
    3. \>
  • Right, this is WEC7. I had NetDCU11 in mind.

    So you can install latest WEC2013 on a NetDCUA9 and check if it is really the OS.

    I test with kernel WEC2013 for imx6 V3.4.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello,


    this all wouldn't be neccessary, if I could access data directly from program into memory.

    Unfortunately there are 2 problems I cannot solve.

    I would like to start tool netstat in background by CreateProcess(), but always a white window is shown shortly on display.

    But the biggest problem is, that I cannot write the standard output of "netstat -n" into memory and process the output.

    I found examples to get output into memory by Pipes, but they are not available on WinEC7.


    I also tried a short program in C#, but also there I cannot write to memory (the property RedirectStandardOutput is not known).

    Also the CreateNoWindow property is not known. Seems that both are not available on WinEC7? I'm wondering, because they should be available in .NET Framework 3.5 ???



    Has someone other ideas, how I could execute "netstat -n" and get output into memory for further operations?


    The original purpose of all that, is to check a port (5900) to detect if a running VNC server has an opened connection.

    Unfortunately the server itself has no interface to get information directly from it.


    I also tried to open a connection by myself on port 5900, but neither bind() nor listen() delivered me an error. Only when I do that twice, I get an error after 2nd call. Why is it possible, to bind() and listen on port 5900, when it is already in use by VNC server?

    According to my understanding it should not be possible and I should get an error, when I access it when already in use? A port should be only available once on one host?


    Best regards, Andy

  • Hello again,


    it seems I had the completely wrong way to do what I wanted. Now I solved it with a small code. Maybe it helps someone...

  • Hello thanks, for you detailed explanation and hint.


    [EDIT] ok think following is nonsense:(

    Anyway, a short comment to your "CreateProcess" above. Netstat is not a command it is an executeable, so maybe following works without showing console:

    BOOL bResult = CreateProcess(T("netstat"), T("-n > NetScan.log"), ...

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

    Edited 3 times, last by fs-support_ZU ().

  • Hello,


    when I execute that, I get following error message in a new window shown on display (WrongParameter.gif).

    When I execute your code with parameter "-n" (only -n without redirection), executable is executed correctly with parameter, but output is shown as expected in new window (Output.gif).

    Seems the problem is the redirection which also causes problems when I execute it directly in shell by telnet with output in files in other directories than root.

  • Hello, yes you are right, I edit my previous post yesterday; "[EDIT] ok think following is nonsense:("!

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.