Solved

tcl/tk process?

Posted on 2002-05-15
11
297 Views
Last Modified: 2013-11-22
Hi,

I am looking for another solution of how to bring an execution of my tcl/tk programme into background besides doing
> prog input &

I want it to be done from within my program "prog" itself i.e.
> prog input
will do the job and I can use this tty to other thing without having to do
Control-Z & bg.

Thanx.
0
Comment
Question by:mafendee
  • 6
  • 5
11 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7014730
if {[string compare $argv {deamon}] == 0} {
  # process goes here
} else {
   exec $argv0 deamon &
   exit
}
exit
0
 

Author Comment

by:mafendee
ID: 7016354
I dont really understand how it should work. My first question, what is deamon, are u referring to "input" from

> prog input

0
 

Author Comment

by:mafendee
ID: 7016392
I dont really understand how it should work. My first question, what is deamon, are u referring to "input" from

> prog input

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7022304
simply use my suggestion as first lines in your "prog"'s file, that's it.
0
 

Author Comment

by:mafendee
ID: 7023389
Basically I wanna know what am I doing. It will be very nice if you could drop a few lines concerning what this code actually does. I was a bit confused with its input parameter.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 7025451
the code actually checks the first command line parameter, if it is not equal "daemon" the script starts itself in background and exits.
Think that was what you want.
0
 

Author Comment

by:mafendee
ID: 7029253
I have tried with your suggestion, but still with some problems...
1. should it be daemon or deamon (in your code)?

If I understood correct, I have done it this way,

if {[string compare $argv {deamon}] == 0} {
       # process goes here   ### A
} else {
       exec $argv0 deamon &  ### B
       exit
}
exit                     ### C

line A: process goes here means all my written code should be placed there, right?

line B: what happen to my command line parameter 'input' from > prog input ?

line C: I am not sure whether I need this 'exit' because it will exit the whole program.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7030588
1. the typo dosn't matter 'cause deamon is a string which I typed equal both times (even I meant daemon:-)

line A: right

line B: use changed code

set d [lindex $argv 0]
if {[string compare $d {deamon}] == 0} {
   set argv [lreplace $argv 0 0 {}]
   # process goes here
} else {
   exec $argv0 deamon $argv &
   exit
}
exit

line C: defensive programming (in case of something goes wrong)
0
 

Author Comment

by:mafendee
ID: 7031933
I see what you meant. I have changed the code, I think you wanted to delete deamon out from this line.
       set argv [lreplace $argv 0 0 {}]
I works better when I change it to
       set argv [lreplace $argv 0 0]
otherwise it will change argv to "{} input".

But, the problem now is that, it is still doesn't work.

If I exclude line C then, the program exit.
If I include line C, two processes were created and the
process still in foreground, no access to terminal still.

Then I include line D
#######################################################
} else {
        catch {exec $argv0 deamon $argv &}
        catch {exec kill [pid] 2>& /dev/null} ### line D
     exit
}
#######################################################
It seems to solve the problem, i.e. start program in background and able to access the terminal for other use.

BUT (hopefully, this is the last problem) at the terminal I have this "Terminated" message. It doesn't seem good if other user use this program.
###########################
sun100 > prog input
Terminated
###########################
I have tried with the /dev/null upthere but it still doesn't work. Any clue?

One more thing, I am using "wish" as my interpreter
#/opt/tools/sun5/bin/wish -f
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 total points
ID: 7032864
wish is ok, 'cause we only use tcl commands which are a subset of wish. I used wish too for my tests ;-)

Are you shure about your "include" and "exclude" statement? is it not the other way around?

For me it works exactly as I posted it here. I don't need catch.
'cause you need to use catch, it sounds like your shell (wish or its parent) is not able to start programs in background. Wired.
0
 

Author Comment

by:mafendee
ID: 7044084
You are right, the "include" and "exclude" things should work the other way round. Anyway, it works good right now.
thanx.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now