Jump to content

Issue Running Scripts From Other Scripts


Mehoron
 Share

Recommended Posts

Hey Everyone,

I'm wondering if anyone is familiar with this issue. Basically, I am having a script which acts as a front end for other scripts. But when running these other scripts, which are in their own directory, the @ScriptDir is seen as the front end script instead of the script I am trying to run. So instead of the child script pulling files it should be from it's own directory it's pulling instead from the master scripts directory.

Here is a snippet of the run code. (Which works great to run the script) Some stuff has been removed or x'ed out due to my work.

Func runscripts()
    For $i = 1 to 100
        $scriptfile= FileReadLine("script.tmp", $i) ;Check the script temp file.
        For $k = 1 to 100
            If StringInStr(FileReadLine("Scripts\ScriptList.txt", $k), $scriptfile) Then ;If the script list contains the script file move on. This is a way we can find the script even if they aren't in order.
                        If <Cut>
                    Else
                    $scriptfilenameraw = FileReadLine("Scripts\ScriptList.txt", $k); Read the raw line.
                    $scriptfilename = StringSplit($scriptfilenameraw, ", ", 1) ; Split the line by it's commas this will produce an array with each split. (This split should include the space)
                    RunWait(@ScriptDir & "\Scripts\" & $scriptfilename[2] ); Run just the script.
                EndIf
            EndIf
        Next
    Next
    
EndFunc
Link to comment
Share on other sites

You can try using FileChangeDir to set the current working directory. Just point it to the directory of the scripts you are calling.

@ScriptDir is the path of a script. It is a macro used by a script in its own code. So if you have two scripts, script1 and script2, the @ScriptDir in script1 is the path of script1 and the @ScriptDir in script2 is the path of script2.

Link to comment
Share on other sites

You can try using FileChangeDir to set the current working directory. Just point it to the directory of the scripts you are calling.

@ScriptDir is the path of a script. It is a macro used by a script in its own code. So if you have two scripts, script1 and script2, the @ScriptDir in script1 is the path of script1 and the @ScriptDir in script2 is the path of script2.

Well that's how it's supposed to work, but in script2 I have it look for files and whatnot in it's own @ScriptDir(I specifically specify this in the second script), but it doesn't work when run from script1. Script2 will try and find or write the files in script1's directory. I can run script2 by itself without any issues at all, but once run from script1 it has problems.

Here is an example of script2 making a temp file.

FileWriteLine(@ScriptDir & "\DataCrawler.tmp", $high)

This is written in script1's directory instead of script2's ONLY when running script2 from script1.

Link to comment
Share on other sites

Ah. You have to set the working directory for your Run calls.

Run($path, $workingdirectory)

When you just do a Run($path) the program you are calling assumes that it is running at the current working directory of the calling script. This makes the @ScriptDir of script2 point to the same location as the @ScripDir of script1. Specifying a working path for Run calls will solve your problem.

Edited by omikron48
Link to comment
Share on other sites

Ah. You have to set the working directory for your Run calls.

Run($path, $workingdirectory)

When you just do a Run($path) the program you are calling assumes that it is running at the current working directory of the calling script. This makes the @ScriptDir of script2 point to the same location as the @ScripDir of script1. Specifying a working path for Run calls will solve your problem.

So there are other issues with this as well, such as, when I RunWait in script1, script2 also waits. Why in the world is my other script inheriting functionality from the main script? And what else is being inherited? When I run a compiled script through the run command I kind of expect it to not pull anything from script1. Especially considering that even if I wanted it to, I would just have it as an include and run script2 as a function.

It seems a bit broken that my autoit EXE is not being run like a normal program.

Link to comment
Share on other sites

Actually, that is how other programs behave when you use a Run without specifying a working directory. What Run actually does is execute the called program at the current working directory of the calling script. If no changes have been made to the current working directory of the calling script, the working directory of the called script would be the execution location of the calling script.

What that means is that if you have a script that Run(s) a script that Run(s) another script, the third script's working directory would be the same as the first script.

As for your RunWait issue, I'm not sure. All RunWait should do is pause script execution of the calling script until the called program finishes execution. If the called script is also paused, there must be something else going on in your second script.

Edited by omikron48
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...