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 8567641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:55:42+00:00 2026-06-11T17:55:42+00:00

I have a tcl code which invokes ping command and returns its response ,

  • 0

I have a tcl code which invokes ping command and returns its response , code is as follows

proc ping-igp {} {
foreach i {
127.0.0.1
200.200.200.1
} {
if { [regexp "0% loss"  [eval exec "ping $i -n 1" ]]} { puts “$i”} else { puts “$i  failed” }
}
}

But while executing it I get o/p as follows,

% proc ping-igp {} {
foreach i {
127.0.0.1
200.200.200.1
} {
if { [regexp "0% loss"  [eval exec "ping $i -n 1" ]]} { puts "$i"} else { puts "
$i  failed" }
}
}
% ping-igp
"127.0.0.1"
Pinging 200.200.200.1 with 32 bytes of data:
Request timed out.
Ping statistics for 200.200.200.1:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
child process exited abnormally
%

I want to know when I’m unable to ping 200.200.200.1 why my code doesn’t process else clause and give o/p ” 200.200.200.1 failed ” in end . I’m matching “0% loss”

Many Thanx.

  • 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-06-11T17:55:43+00:00Added an answer on June 11, 2026 at 5:55 pm

    You need to catch the exec call to ping, in case it returns an error. Here’s your code modified to use catch.

    proc ping-igp {} {
    foreach i {
      127.0.0.1
      200.200.200.1
    } {
    if {[catch {exec ping $i -n 1} result]} { set result 0 } 
    if { [regexp "0% loss"  $result]} { puts "$i"} else { puts "$i  failed" }
    }
    }
    

    Running it now gives:

    % ping-igp
    127.0.0.1
    200.200.200.1  failed
    %
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which based on the variable op invokes either min
Currently I have some code that is doing an SFTP via expect/tcl. Its something
I have the following code in tcl .. proc GetPPVSummary {} { global LIBRARY
I have the following piece of TCL code: #wrong format: set in_val 12 0
I have a question about the following code in TCL/EXPECT: expect { timeout {
I have a question about variable scope in TCL, I have the following code:
I have a question about string in TCL: HANDLE_NAME /group1/team1/RON proc HANDLE_NAME {playerName} {
I have a question about upvar command in TCL. Using upvar command, we have
I have code here proc checkPrime {no} { set i 1 set count 0
If I have a proc that needs to return an array to its caller,

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.