LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-10-2012, 10:43 PM   #1
haiying7
LQ Newbie
 
Registered: Nov 2011
Location: Sydney, Australia
Posts: 15

Rep: Reputation: Disabled
Question How to import a variable from C++ program to TCL script? THX


Hi,

Is there any way to call c++ parameters in TCL program. For example, in TCL script, I want to set a variable which is defined in a C++ program. How can I pass this variable from C++ to TCL?

I`ll appreciate if anyone can help.

Thanks.
 
Old 01-15-2012, 04:32 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
As these are separate applications/processes, I think you would need to set up some kind of inter-process communication like a named pipe, or even just printing the variables value to stdout.
 
Old 01-16-2012, 07:53 AM   #3
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
Hi.

I'm not certain as to what you mean by import, but here is am example of a tcl script running a c++ executable, saving and displaying the result:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate tcl script calling c++ executable.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C tclsh g++

pl " Input cpp source:"
cat one.cpp
g++ one.cpp

pl " Input tcl script:"
cat tcl1

pl " Results, tcl script runs cpp executable, saves result:"
./tcl1

rm -f a.out
exit 0
producing:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
GNU bash 3.2.39
tclsh 8.4
g++ (Debian 4.3.2-1.1) 4.3.2

-----
 Input cpp source:
#include <iostream>

using namespace std;

int main()
{
  cout << " Hello, world from c++" << endl;
  return ( 0 );
}

-----
 Input tcl script:
#!/usr/bin/env tclsh

# @(#) tcl1     Demonstrate tcl return output from system executable.

puts stdout ""
set message [ exec ./a.out ]
puts stdout $message

exit 0


-----
 Results, tcl script runs cpp executable, saves result:

 Hello, world from c++
Adapted from http://www.tcl.tk/man/tcl8.4/TclCmd/exec.htm#M26

Best wishes ... cheers, makyo
 
Old 09-24-2012, 03:51 PM   #4
manolin
LQ Newbie
 
Registered: Jan 2012
Posts: 6

Rep: Reputation: Disabled
question

hi

did you manage to solve ur problem?
is so, would plz help me out
with it.
i appreciate any help.
 
Old 09-24-2012, 07:31 PM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
Quote:
did you manage to solve ur problem?
is so, would plz help me out
with it.
please spell out your words

please SHOW me where in the dictionary is
" ur" ??????
or
"plz" ???????

http://www.oed.com/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] set environment variable is tcl sharky Programming 1 04-22-2011 04:51 PM
[SOLVED] How to : setting PATH variable for TCL raju.mopidevi SUSE / openSUSE 18 02-22-2009 11:14 AM
Imp for me: How to pass a variable from .tcl file to Makefile sun_sun Programming 6 11-27-2007 05:26 AM
how do you import bash script to a c++ program? jaepi Programming 2 05-02-2007 03:28 AM
How to start a Tcl/Tk script by simply invoking the script file itself ? cyu021 Programming 2 10-10-2004 11:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration