Professional Web Applications Themes

Threads for dummies - Ruby

Hi Can somone please tell me howto handle threads in the code below <code ex> def start_app system("echo #{$passwd}|sudo -S #{$appl}"} $passwd.value = '' $appl.value = '' end </code ex> Works fine, but the system(....) thing, grabs focus ontil the application stops. So far Ive tried to write something like: <code ex > def start_app Thread.new($passwd, $appl) do t = Thread.current passwd = t[:$passwd] appl = t[:$appl] system("echo #{passwd}|sudo -S #{appl}"} end $passwd.value = '' $appl.value = '' end </code ex> This dosnt work What I want is to create a subprocess running the programm, and return to reset the ...

  1. #1

    Default Threads for dummies

    Hi
    Can somone please tell me howto handle threads in the code below
    <code ex>
    def start_app
    system("echo #{$passwd}|sudo -S #{$appl}"}
    $passwd.value = ''
    $appl.value = ''
    end
    </code ex>
    Works fine, but the system(....) thing, grabs focus ontil the application
    stops.

    So far Ive tried to write something like:
    <code ex >
    def start_app
    Thread.new($passwd, $appl) do
    t = Thread.current
    passwd = t[:$passwd]
    appl = t[:$appl]
    system("echo #{passwd}|sudo -S #{appl}"}
    end
    $passwd.value = ''
    $appl.value = ''
    end
    </code ex>

    This dosnt work

    What I want is to create a subprocess running the programm, and return to
    reset the variables.
    --
    /Sv-e
    Svend-Erik Guest

  2. #2

    Default Re: Threads for dummies ver 0001

    Svend-Erik Kjr Madsen wrote:
     

    Got this wrong 
    $passwd = t[:passwd]
    $appl = t[:appl]
     

    --
    /Sv-e
    Svend-Erik Guest

  3. #3

    Default Re: Threads for dummies


    "Svend-Erik Kjr Madsen" <dk> schrieb im
    Newsbeitrag news:40260d72$0$17636$dk.telia.net... 
    application 
    to 

    It's generally a bad idea to let the sub program reset the variables after
    it is done because you can't control the point in time and that might have
    all kinds of strange effects. Better use local variables. Two
    approaches:

    def start_app(appl, passwd)
    Thread.new do
    system("echo #{passwd}|sudo -S #{appl}"}
    end
    end

    Or, if you don't want to define a method for this, you should proceed like
    this:

    Thread.new($appl, $passwd) do |app, pass|
    system("echo #{pass}|sudo -S #{app}"}
    end

    This way "app" and "pass" are local variables and as soon as you started
    the thread you can change values of those global variables to whatever you
    like and they don't interfere.

    Regards

    robert

    Robert Guest

Similar Threads

  1. Testing server for dummies
    By dkd;alkje;oihp[oihjl in forum Macromedia Dynamic HTML
    Replies: 14
    Last Post: December 3rd, 08:41 PM
  2. Javascript forms for dummies?
    By samanthamerley in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: July 22nd, 04:34 AM
  3. asp for dummies
    By DanManOZ in forum Macromedia Dynamic HTML
    Replies: 1
    Last Post: February 10th, 01:46 PM
  4. Cartography for Dummies
    By citizenslave in forum Macromedia Freehand
    Replies: 2
    Last Post: June 3rd, 04:46 AM
  5. Using Dummies when skining a character
    By 3dsolve in forum Macromedia Director 3D
    Replies: 0
    Last Post: February 17th, 10:48 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139