From: Dave on 2 Jun 2010 11:15 Gang, I'm still working on the same script from the post yesterday (which had its previous problem resolved this morning). I'm issuing a 'mv' command via spawn but the script isn't throwing any errors, however the file thats attempted to be moved is not moving either. I'm sure there is an error message being displayed by the 'mv' command, but I don't know how to access the message. I've tried using 'catch' and can display an error code, but not the message (as shown below). Any help on being able to print the error message so I can see (whether to screen or file) would greatly be appreciated. catch { eval spawn -noecho $syntax } curr_result send_user "error is: $curr_result\n"; NOTE: $syntax contains the command to execute and is passed into the script via a parameter value. At present, I'm just trying something simple like "mv a.txt b.txt" where a.txt doesn't exist so I can print out the error message. Thanks, Dave
From: Alexandre Ferrieux on 2 Jun 2010 11:22 On Jun 2, 5:15 pm, Dave <hende...(a)gmail.com> wrote: > Gang, > > I'm still working on the same script from the post yesterday > (which had its previous problem resolved this morning). I'm issuing a > 'mv' command via spawn but the script isn't throwing any errors, > however the file thats attempted to be moved is not moving either. > I'm sure there is an error message being displayed by the 'mv' > command, but I don't know how to access the message. I've tried using > 'catch' and can display an error code, but not the message (as shown > below). Any help on being able to print the error message so I can > see (whether to screen or file) would greatly be appreciated. > > catch { eval spawn -noecho $syntax } curr_result > send_user "error is: $curr_result\n"; > > NOTE: $syntax contains the command to execute and is passed into the > script via a parameter value. At present, I'm just trying something > simple like "mv a.txt b.txt" where a.txt doesn't exist so I can print > out the error message. From what you wrote here and in the other thread, I don't see a good reason to use Expect. Are there other considerations that would change this impression ? Do you need to control interactive things like telnet, ssh, ftp, rlogin ? If not, just do it with vanilla tclsh. Then you'll see that catch {exec sh -c $syntax} curr_result does retrieve the error. Alternatively, you can tell Tcl to let the stderr of the commands flow to the console unimpeded, and just get the binary success information: set nok [catch {exec sh -c $syntax 2>@ stderr}] -Alex
From: Dave on 2 Jun 2010 12:58 On Jun 2, 11:22 am, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> wrote: > On Jun 2, 5:15 pm, Dave <hende...(a)gmail.com> wrote: > > > > > Gang, > > > I'm still working on the same script from the post yesterday > > (which had its previous problem resolved this morning). I'm issuing a > > 'mv' command via spawn but the script isn't throwing any errors, > > however the file thats attempted to be moved is not moving either. > > I'm sure there is an error message being displayed by the 'mv' > > command, but I don't know how to access the message. I've tried using > > 'catch' and can display an error code, but not the message (as shown > > below). Any help on being able to print the error message so I can > > see (whether to screen or file) would greatly be appreciated. > > > catch { eval spawn -noecho $syntax } curr_result > > send_user "error is: $curr_result\n"; > > > NOTE: $syntax contains the command to execute and is passed into the > > script via a parameter value. At present, I'm just trying something > > simple like "mv a.txt b.txt" where a.txt doesn't exist so I can print > > out the error message. > > From what you wrote here and in the other thread, I don't see a good > reason to use Expect. Are there other considerations that would change > this impression ? Do you need to control interactive things like > telnet, ssh, ftp, rlogin ? > > If not, just do it with vanilla tclsh. > Then you'll see that > > catch {exec sh -c $syntax} curr_result > > does retrieve the error. > Alternatively, you can tell Tcl to let the stderr of the commands flow > to the console unimpeded, and just get the binary success information: > > set nok [catch {exec sh -c $syntax 2>@ stderr}] > > -Alex Thanks for the reply Alex. Actually I'm using Expect because certain tasks must be handled via a script and sometimes require the use of sudo or su. Expect handles all the prompting for passwords so the user can just click a button and have a 'success' or 'failure' (with message - for the admin). Don't worry the scripts don't store passwords, instead they are passed by a submission prompt from the GUI each time and passed to the Expect script. Currently I'm using the 'spawn' syntax to launch commands, should I be using 'exec' instead? Will there be a problem with 'exec' (as no issues to report using 'spawn' so far) with the use of sudo or su? If 'spawn' is still the preferred method, can I just substitute 'exec sh - c' with 'spawn' in the afore mentioned examples? Thanks, Dave
From: Dave on 8 Jun 2010 11:18 On Jun 2, 12:58 pm, Dave <hende...(a)gmail.com> wrote: > On Jun 2, 11:22 am, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> > wrote: > > > > > On Jun 2, 5:15 pm, Dave <hende...(a)gmail.com> wrote: > > > > Gang, > > > > I'm still working on the same script from the post yesterday > > > (which had its previous problem resolved this morning). I'm issuing a > > > 'mv' command via spawn but the script isn't throwing any errors, > > > however the file thats attempted to be moved is not moving either. > > > I'm sure there is an error message being displayed by the 'mv' > > > command, but I don't know how to access the message. I've tried using > > > 'catch' and can display an error code, but not the message (as shown > > > below). Any help on being able to print the error message so I can > > > see (whether to screen or file) would greatly be appreciated. > > > > catch { eval spawn -noecho $syntax } curr_result > > > send_user "error is: $curr_result\n"; > > > > NOTE: $syntax contains the command to execute and is passed into the > > > script via a parameter value. At present, I'm just trying something > > > simple like "mv a.txt b.txt" where a.txt doesn't exist so I can print > > > out the error message. > > > From what you wrote here and in the other thread, I don't see a good > > reason to use Expect. Are there other considerations that would change > > this impression ? Do you need to control interactive things like > > telnet, ssh, ftp, rlogin ? > > > If not, just do it with vanilla tclsh. > > Then you'll see that > > > catch {exec sh -c $syntax} curr_result > > > does retrieve the error. > > Alternatively, you can tell Tcl to let the stderr of the commands flow > > to the console unimpeded, and just get the binary success information: > > > set nok [catch {exec sh -c $syntax 2>@ stderr}] > > > -Alex > > Thanks for the reply Alex. Actually I'm using Expect because certain > tasks must be handled via a script and sometimes require the use of > sudo or su. Expect handles all the prompting for passwords so the > user can just click a button and have a 'success' or 'failure' (with > message - for the admin). Don't worry the scripts don't store > passwords, instead they are passed by a submission prompt from the GUI > each time and passed to the Expect script. > > Currently I'm using the 'spawn' syntax to launch commands, should I be > using 'exec' instead? Will there be a problem with 'exec' (as no > issues to report using 'spawn' so far) with the use of sudo or su? If > 'spawn' is still the preferred method, can I just substitute 'exec sh - > c' with 'spawn' in the afore mentioned examples? > > Thanks, > Dave bump for help
From: Alexandre Ferrieux on 8 Jun 2010 12:11 On Jun 8, 5:18 pm, Dave <hende...(a)gmail.com> wrote: > On Jun 2, 12:58 pm, Dave <hende...(a)gmail.com> wrote: > > > > > > > On Jun 2, 11:22 am, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> > > wrote: > > > > On Jun 2, 5:15 pm, Dave <hende...(a)gmail.com> wrote: > > > > > Gang, > > > > > I'm still working on the same script from the post yesterday > > > > (which had its previous problem resolved this morning). I'm issuing a > > > > 'mv' command via spawn but the script isn't throwing any errors, > > > > however the file thats attempted to be moved is not moving either. > > > > I'm sure there is an error message being displayed by the 'mv' > > > > command, but I don't know how to access the message. I've tried using > > > > 'catch' and can display an error code, but not the message (as shown > > > > below). Any help on being able to print the error message so I can > > > > see (whether to screen or file) would greatly be appreciated. > > > > > catch { eval spawn -noecho $syntax } curr_result > > > > send_user "error is: $curr_result\n"; > > > > > NOTE: $syntax contains the command to execute and is passed into the > > > > script via a parameter value. At present, I'm just trying something > > > > simple like "mv a.txt b.txt" where a.txt doesn't exist so I can print > > > > out the error message. > > > > From what you wrote here and in the other thread, I don't see a good > > > reason to use Expect. Are there other considerations that would change > > > this impression ? Do you need to control interactive things like > > > telnet, ssh, ftp, rlogin ? > > > > If not, just do it with vanilla tclsh. > > > Then you'll see that > > > > catch {exec sh -c $syntax} curr_result > > > > does retrieve the error. > > > Alternatively, you can tell Tcl to let the stderr of the commands flow > > > to the console unimpeded, and just get the binary success information: > > > > set nok [catch {exec sh -c $syntax 2>@ stderr}] > > > > -Alex > > > Thanks for the reply Alex. Actually I'm using Expect because certain > > tasks must be handled via a script and sometimes require the use of > > sudo or su. Expect handles all the prompting for passwords so the > > user can just click a button and have a 'success' or 'failure' (with > > message - for the admin). Don't worry the scripts don't store > > passwords, instead they are passed by a submission prompt from the GUI > > each time and passed to the Expect script. > > > Currently I'm using the 'spawn' syntax to launch commands, should I be > > using 'exec' instead? Will there be a problem with 'exec' (as no > > issues to report using 'spawn' so far) with the use of sudo or su? If > > 'spawn' is still the preferred method, can I just substitute 'exec sh - > > c' with 'spawn' in the afore mentioned examples? > > > Thanks, > > Dave > > bump for help Sorry I can only offer help _outside_ Expect ;-) If no Expect expert steps forth, I can propose this simple idea: - use Expect-savvy primitives like 'spawn' for sudo and other terminal interaction - use [exec] (Tcl is a superset of Expect AFAIK) for the rest. -Alex
|
Next
|
Last
Pages: 1 2 3 Prev: sending email with smtp package Next: Xming X11 server and fullscreen mode |