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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:07:47+00:00 2026-05-15T06:07:47+00:00

i wrote a script for spawing the bc command package require Expect proc bc

  • 0

i wrote a script for spawing the bc command

package require Expect

proc bc {eq} {
    spawn e:/GnuWin32/bc/bin/bc
    send "$eq\r"
    expect -re "(.*)\r"
    return "$expect_out(0,string)"
}

set foo "9487294387234/sqrt(394872394879847293847)"

puts "the valule [bc $foo]"

how to get the output from this. When i am running this one i get ouput like this

bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
9487294387234/sqrt(394872394879847293847)
477
can't read "expect_out(0,string)": no such element in array
    while executing
"return "The values is $expect_out(0,string)""
    (procedure "bc" line 6)
    invoked from within
"bc $foo"
    invoked from within
"puts "the valule [bc $foo]""
    (file "bc.tcl" line 21)

how to resolve this one.

  • 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-15T06:07:48+00:00Added an answer on May 15, 2026 at 6:07 am

    The problem is that it’s not matching what you expect. (Cue the Jamie Zawinski quote.)

    Try this:

    package require Expect
    proc bc eq {
        spawn bc; # It's on my path...
        send $eq\r
        set timeout 1; # 1 second
        expect timeout {} -re {[^\r\n]+} {
            set lastline $expect_out(0,string)
            exp_continue
        }
        close
        return $lastline
    }
    puts >>[bc 9487294387234/sqrt(394872394879847293847)]<<
    

    I get this output…

    spawn bc
    9487294387234/sqrt(394872394879847293847)
    bc 1.06
    Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
    This is free software with ABSOLUTELY NO WARRANTY.
    For details type `warranty'. 
    9487294387234/sqrt(394872394879847293847)
    477
    >>477<<
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently wrote a script which queries PyPI and downloads a package; however, the
I wrote a script to send the contents of a contact form (first name,
I wrote a script to run a command-line program with different input arguments and
I wrote some script in a site. The script makes a new spreadsheet and
I wrote a script parsing a .csv file in groovy using tokenize, which ended
I wrote this script which counts occurrences of particular pattern in a given file.
I wrote a script that uses xcodebuild to generate an AdHoc build of an
I wrote this script to for a contact form on my website, everything works
I have wrote a script to detect when I reach the div element which
I have wrote a script that was run from a spreadsheet. I had One

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.