Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7038715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:42:08+00:00 2026-05-28T01:42:08+00:00

When I execute netstat -a |find /C $portNumber in command prompt I get the

  • 0

When I execute netstat -a |find /C $portNumber in command prompt I get the total number of lines where the given port number exists.

I want to get that same count in any variable so that I can check whether the port is already occupied or free in NSIS.

I am excuting the below command and I tried in many ways, but I’m not able to get the output of the ExecDos::exec in a variable or in the stack.

ExecDos::exec "netstat -a |find /C '$portNumber'| $output"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:42:09+00:00Added an answer on May 28, 2026 at 1:42 am

    To enable shell behavior you have to execute cmd.exe /C yourcommand (Or expand %ComSpec% with ExpandEnvStrings but hardcoding cmd.exe is ok if you don’t support Win9x)

    Or you can try the ExecCmd plug-in which does this for you (But it has fewer options so you would have to redirect the output to a file)

    nsExec::ExecToStack with the cmd prefix should also work…

    Edit:

    Here is a working example (I used nsExec since it part of the default install)

    !include LogicLib.nsh
    section
    ExpandEnvStrings $0 %COMSPEC%
    StrCpy $1 445 ;Port number
    nsExec::ExecToStack '"$0" /C netstat -an|find /C ":$1"'
    Pop $0
    ${If} $0 = 0
        Pop $0
        MessageBox mb_ok "Port count=$0"
    ${Else}
        ; Port not open...
    ${EndIf}
    sectionend
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I execute a select to get the structure of a table. I want to
I want to execute a command line tool to process data. It does not
I execute an INSERT INTO statement cursor.execute(INSERT INTO mytable(height) VALUES(%s),(height)) and I want to
How do I execute the Copy Web Site command for an ASP.NET project in
Please execute the following queries first to set up so that you can help
First execute these tables and data dumps :- CREATE TABLE IF NOT EXISTS `Tags`
I execute the following bash script: #!/bin/bash version=$1 echo $version sed 's/\${version.number}/$version/' template.txt >
How execute command via shell and return the complete output as a string using
Whenever I execute the gmaven plugin, I get the following problem org.apache.maven.lifecycle.LifecycleExecutionException: Internal error
I need to write a program that displays this information: netstat TCP / UDP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.