Jump to content

Yikes - why did my script break?


Recommended Posts

I have a script that was working flawlessly. I got a new computer, installed everything and restored my scripts from backup. I isntalled the latest AutoIT and I'm not 100% sure what version I was using before (probably whatever was current ~ Nov/Dec 09). But now my script fails. This is the pertinent function:

Func _pLink ()
    $plink = @ProgramFilesDir & "\putty\plink.exe"
    $server = " root@server"
    $command_du = " cd /home2; du -h --max-depth=1"
    $PID = Run ( $plink & $server & $command_du, @ScriptDir, @SW_HIDE, $STDOUT_CHILD )
    dim $rawlist
    While 1
        $_ = StdoutRead($PID)
        If @error Then ExitLoop
        If @extended > 0 Then
            $rawlist = $rawlist & $_
        EndIf
    WEnd
    $rawlist = StringSplit ( $rawlist, @CRLF )
    Dim $myjoblist[1] = ["foobar"]
    For $i = 1 to $rawlist[0]
        $tabpos = StringInStr ( $rawlist[$i], @TAB )
        $_job = StringMid ( $rawlist[$i], $tabpos + 3 )
        $_size = StringLeft ( $rawlist[$i], $tabpos )
        Switch $_job
            Case "lost+found", "test", "tailwind", "rrtest", "rona", ""
                ;do nothing
            Case Else
                _ArrayAdd ( $myjoblist, $_job & "=" & $_size )
        EndSwitch
    Next
    $myjoblist[0] = UBound ( $myjoblist ) - 1
    _ArraySort ( $myjoblist, 0, 1 )
    Return $myjoblist
EndFunc

And the error I get is, "Unable to read from standard input: The handle is invalid."

My presumption is that for whatever reason it doesn't like the line:

$PID = Run ( $plink & $server & $command_du, @ScriptDir, @SW_SHOW, $STDOUT_CHILD )

What I don't get is that it worked just fine before and nothing really changed... plink is installed to the same location, my @ProgramFilesDir is the same as before and so is the @ScriptDir - not that it should matter. I ClipPut'ed the line so that I could manually test the command in a CMD box and it worked fine.

Did something change recently with Run or StdoutRead that could affect this? I read the features log and didn't see anything relevant.

Thanks.

Link to comment
Share on other sites

I hooked up my old harddrive and ran the autoit that was still on there... and my script is fine.

So is is something that changed between V3.3.0.0 and now. I've again gone through the help file's changelog and don't see anything pertaining to how run() works.

Any ideas?

Link to comment
Share on other sites

I've noticed the new addition to the help file listing for Run, where it states that paths with spaces must be enclosed in spaces. I've tried every quote (single, double) and space configuration I could think of... if it works in a CMD box it fails in Autoit and if it works in Autoit it seems to fail in the CMD box... and in no case can I get it to perform as expected. In other words, the configurations that don't return an error still didn't work (they don't run the program correctly).

Bottom line... this is the command I want to run as I would type it in a cmd box:

"C:\Program Files\putty\plink.exe" root@server cd /home2; du -h --max-depth=1

Placing the last part in quotes also works:

"C:\Program Files\putty\plink.exe" root@server "cd /home2; du -h --max-depth=1"

But placing the whole thing does not:

"C:\Program Files\putty\plink.exe root@server cd /home2; du -h --max-depth=1"

Of the three, only the latter works in terms of not coming up with the aformentioned error but it doesn't work in terms of actually functioning.

Frustrated!

Edited by LondonNDIB
Link to comment
Share on other sites

Dude - stop bumping your post. :mellow:

I understand you are frustrated but that's not a reason to do this.

The "Edit" button on this forum exists for a purpose.

When somebody will have an answer they will post it, until then, try to debug your script.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

"Dude"... chill out. We disagree on what a "bump" is. You're not alone in your thinking, but you're wrong on what the "Edit" button is exists for.

If I was putting useless posts solely for the purpose of getting my topic noticed, that would be a bump. I was adding information to the post. If I just edit it, then someone who reads the post and subsequently re-visits it would have no reason to believe I've made any material additions. As well, perhaps someone subscribed to the topic and it would just ruin their day if they didn't get the subsequent details I posted. They wouldn't get a notification if it were an edit.

But thanks for bumping my post... maybe it will get noticed now.

Link to comment
Share on other sites

There are 2 methods that should work

$plink = FileGetShortname(@ProgramFilesDir) & "\putty\plink.exe"

or

$plink = '"' & @ProgramFilesDir) & '"' & "\putty\plink.exe"

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I agree they should (but so should the original)... but they don't.

The first produces the same AutoIt error mentioned (yes it works in the older version but not in the newer one).

The second produce a valid run... except that it does not execute the program correctly. That is, the syntax works from autoit's perspective but plink returns a "host not recognized" error and it immediately closes. The syntax, in other words, is not consistent with what is required to run the script from a CMD box, for example.

Link to comment
Share on other sites

I haven't, no. I thought that was more for Windows built-in aps like notepad, IE, etc. Besides, from what I can tell it doesn't offer the STD pipes that run does, and that's required.

Keep in mind my script worked fine in V3.3.0.0 so I'd like to focus on what changed since then rather than looking at this like a "how to" question. If nothing was supposed to have changed in this regard, then we're looking at a bug in the latest AutoIt version, not an error in my script.

Edited by LondonNDIB
Link to comment
Share on other sites

Again, there's nothing wrong with the syntax of my original code in terms of whether the underlying command is valid or not. Yes, it works in a CMD console (I believe I said that numerous times, no? Sorry if I wasn't clear on that point).

Again, the question is what has changed since V3.3.0.0 that makes it not work. It worked fine in V3.3.0.0 and there's nothing documented that I can tell that should have broken the script in the subsequent versions.

Link to comment
Share on other sites

Again, there's nothing wrong with the syntax of my original code in terms of whether the underlying command is valid or not. Yes, it works in a CMD console (I believe I said that numerous times, no? Sorry if I wasn't clear on that point).

Again, the question is what has changed since V3.3.0.0 that makes it not work. It worked fine in V3.3.0.0 and there's nothing documented that I can tell that should have broken the script in the subsequent versions.

Sorry, missed the part at the end of your first post where you said "I ClipPut'ed the line so that I could manually test the command in a CMD box".

Just seen it too often where people say "I've done this and it's exactly like before and now it's not working" and it turns out it it wasn't "exactly" the same. Anyway...

When you say you hooked up your old drive and ran the old AutoIt and it worked, did you run an already compiled version of the script, or just run it using the old interpreter?

Have you tried compiling with the old interpreter/version in your new environment to see if it still works?

Just trying to rule out any permissions/configuration issues...

BTW, just downloaded and installed putty package, ran your script as in your first post, and it attaches to the console perfectly under 3.3.4.0 and beta 3.3.5.6 on Win XP Pro w/ SP3

Hope that helps and makes up for my not paying closer attention first time around :mellow:

Link to comment
Share on other sites

I haven't been able to make this hopefully comparable test script break:

#include "Constants.au3"

$plink = @ProgramFilesDir & "\putty\plink.exe"
$server = " user@ipaddress"
$command_du = " cd home2; ls"
Dim $STD_IN_AND_OUT = BitOR($STDIN_CHILD, $STDOUT_CHILD)
$PID = Run ( $plink & $server & $command_du, @ScriptDir, @SW_HIDE, $STD_IN_AND_OUT )
dim $rawlist

StdinWrite($PID, "asaNisiMasa" & @CRLF)

While 1
    $_ = StdoutRead($PID)
    If @error Then ExitLoop
    If @extended > 0 Then
    $rawlist = $rawlist & $_
    EndIf
WEnd

MsgBox(0, "Debug", $rawlist)

...on a XPSP2 32bit VMWare test machine, using AutoIt3 v3.3.0.0 release, v3.3.4.0 release and v3.3.5.6 Beta, both uncompiled and compiled.

LondonNDIB, when you said you were getting a "Unable to read from standard input: The handle is invalid." error, was that actually appearing in SciTE's results pane, correct? I'm guessing that since you have no password entry apparent in your example that you've got your PuTTY et al. environment configured to use keyfile authentication, but the references that I see on the Web to that Plink error indicate that it comes from Plink trying to read a password from STDIN when it isn't being provided by a parent program.

Hope this helps.

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

Sorry, missed the part at the end of your first post where you said "I ClipPut'ed the line so that I could manually test the command in a CMD box".

Just seen it too often where people say "I've done this and it's exactly like before and now it's not working" and it turns out it it wasn't "exactly" the same. Anyway...

When you say you hooked up your old drive and ran the old AutoIt and it worked, did you run an already compiled version of the script, or just run it using the old interpreter?

Have you tried compiling with the old interpreter/version in your new environment to see if it still works?

Just trying to rule out any permissions/configuration issues...

BTW, just downloaded and installed putty package, ran your script as in your first post, and it attaches to the console perfectly under 3.3.4.0 and beta 3.3.5.6 on Win XP Pro w/ SP3

Hope that helps and makes up for my not paying closer attention first time around :mellow:

More than makes up for it, thank you :(

I ran it using the old interpreter. There's actually really nothing different between my old setup and new except for updated hardware. In both cases it was running Windows 7 Pro. Just when I got around to installing AutoIt after the upgrade, I decided to go with the newest version rather than using the old one.

A compiled version (compiled before, so using the older setup) works perfectly so it shouldn't be a permissions issue. However, I can't practically use a compiled version because I often need to adjust variables in the script before running.

Since it works with the old compiler, I can really just call this a non-issue because I have a solution that works for me... but I would think the developers would want to know why a fairly basic function like run changed such that this script broke by no other cause than compiler version when there's no documented change in that function's operation.

Edited by LondonNDIB
Link to comment
Share on other sites

...on a XPSP2 32bit VMWare test machine, using AutoIt3 v3.3.0.0 release, v3.3.4.0 release and v3.3.5.6 Beta, both uncompiled and compiled.

LondonNDIB, when you said you were getting a "Unable to read from standard input: The handle is invalid." error, was that actually appearing in SciTE's results pane, correct? I'm guessing that since you have no password entry apparent in your example that you've got your PuTTY et al. environment configured to use keyfile authentication, but the references that I see on the Web to that Plink error indicate that it comes from Plink trying to read a password from STDIN when it isn't being provided by a parent program.

Hope this helps.

Yes, you are correct - keyfile. I think the way that AutoIT is passing the command line parameters has changed in some way and that's causing this issue. Perhaps plink isn't getting the parameters in a way it recognizes such that it understand the implied authentication scheme.

I will try to incorporate your script and see if it helps. I can't immediately see why it would (the only difference being "Dim $STD_IN_AND_OUT = BitOR($STDIN_CHILD, $STDOUT_CHILD)", right?) but I'll do some testing.

Otherwise maybe the latest versions of AutoIT have some slight incompatibility with newer versions of Windows? Because you're using XP and having no troubles.

Edited by LondonNDIB
Link to comment
Share on other sites

My example is just calling Run in a way that give AutoIt the means to send input (with StdinWrite) to the child program that you'd normally provide by typing. I know that I kind of obfuscated things by throwing in the BitOR, but that really is the proper way to combine flag options for a function parameter.

If you really feel that there's a bug we'd need to narrow it down to the closest versions that don't and do exhibit the problem, and come up with a kiss-of-death script that can replicate the problem without being tied to particular machines (i.e. your client and server PCs).

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

Well, ultimately I suppose now that I have a working solution... I guess I don't care if the "bug" (if that's what it is) is fixed. I don't... you might. From my POV, my script works as-written on one machine with V3.3.0.0 doing the compiling and does not work in the exact same environment with the latest version. Something changed, and that something was not (apparently) documented. However, if you're stating that your suggested line is the proper way I should have done it in the first place (and I take your word for it, certainly), well then I suppose the "bug" could have been with the previous version for allowing an incorrect syntax to be used and that was fixed (or made more strict) subsequently.

I'm more than willing to accept that I should have used that line previously, therefore "my bad" and I thank you for the help.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...