JustinM Posted September 14, 2016 Share Posted September 14, 2016 I am having trouble calling a script 1 folder into my script. Example below. This is how i have the folders setup: Root Folder\Folder1(This is where the AutoIt.exe will go)\Folder2(This is where my Python script will go). How do I call my python script from the autoit script without calling the entire path(C:\users\example\desktop\Root Folder\Folder1\Folder2\python.exe). I would like to have it act like so -- .\Folder2\python.exe. I just need it to move into Folder2 and ignore the whole c:\users\example\desktop...etc Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 14, 2016 Moderators Share Posted September 14, 2016 So, if your script is in C:\Test, for example, and the python script is in C:\Test\Python, you would just call it like this: @ScriptDir & "\Python\<scriptname>" "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
JustinM Posted September 14, 2016 Author Share Posted September 14, 2016 (edited) 10 minutes ago, JLogan3o13 said: So, if your script is in C:\Test, for example, and the python script is in C:\Test\Python, you would just call it like this: @ScriptDir & "\Python\<scriptname>" Thank you. What would be best to call the python script? ShellExecute(@scriptdir & "\Folder2\python.exe") --- Doing it this way, the script quickly opens and closes like something is wrong Edited September 14, 2016 by JustinM Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 14, 2016 Moderators Share Posted September 14, 2016 I am assuming your python script is compiled? If so, is it doing what is expected? If it is not, then try Run instead of ShellExecute. Or try manually running the Python executable from the command line. Does it work then? Really can't offer much more without knowing what your code is doing. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
JustinM Posted September 14, 2016 Author Share Posted September 14, 2016 3 minutes ago, JLogan3o13 said: I am assuming your python script is compiled? If so, is it doing what is expected? If it is not, then try Run instead of ShellExecute. Or try manually running the Python executable from the command line. Does it work then? Really can't offer much more without knowing what your code is doing. When I run the python script from cmd and/or manually, it works. Below is a copy of my code #RequireAdmin DirRemove("C:\Users\Administrator\Desktop\Heaven_Scores", 1) Sleep(300) DirRemove("C:\Users\Public\Desktop\Heaven_Scores", 1) Sleep(300) ShellExecute(@ScriptDir & "\automation\AutoHeaven.py") Sleep(300) WinWait('Unigine Heaven Benchmark 4.0 Advanced (Direct3D11)') WinActivate('Unigine Heaven Benchmark 4.0 Advanced (Direct3D11)') Sleep(300) While ProcessExists("Heaven.exe") WinActivate('Unigine Heaven Benchmark 4.0 Advanced (Direct3D11)') Send("{VOLUME_MUTE}") Sleep(30000) ;Sleep(21500000) ProcessClose("python.exe") Sleep(1000) ProcessClose("browser_x86.exe") Sleep(1000) ProcessClose("Heaven.exe") Sleep(1000) DirMove("C:\Users\Administrator\Desktop\Heaven_Scores", "C:\Users\Public\Desktop\Heaven_Scores", 1) WEnd Exit Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 14, 2016 Moderators Share Posted September 14, 2016 (edited) Ok, so in answer to my last question your python script is not compiled to an exe. That means you have to give the path to your interpreter, unless you've added the interpreter to your PATH environment variable. I am guessing something like this: ShellExecute("C:\Python.exe", @ScriptDir & "\automation\AutoHeaven.py") Edited September 14, 2016 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
JustinM Posted September 14, 2016 Author Share Posted September 14, 2016 4 minutes ago, JLogan3o13 said: Ok, so in answer to my last question your python script is not compiled to an exe. That means you have to give the path to your interpreter, unless you've added the interpreter to your PATH environment variable. I am guessing something like this: ShellExecute("C:\Python.exe", @ScriptDir & "\automation\AutoHeaven.py") Is it possible to call C:\Python.exe from Folder3? Is it possible to combine 2 into 1? -- ShellExecute(@scriptdir & "\python\python.exe" & "..\automation\python.exe" Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 14, 2016 Moderators Share Posted September 14, 2016 Use Run instead then: Run(@ScriptDir & "\Folder1\Python.exe " & @ScriptDir & "\Folder2\Python.py") Or, if there is any potential you'll be changing the paths at some point, best practice would be to define them in your script first: Local $sPython = @ScriptDir & "\Folder1\Python.exe" Local $sPyScript = @ScriptDir & "\Folder2\Python.py" Then if you do have to change them, you only need to do so once. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
JustinM Posted September 14, 2016 Author Share Posted September 14, 2016 (edited) 53 minutes ago, JLogan3o13 said: Use Run instead then: Run(@ScriptDir & "\Folder1\Python.exe " & @ScriptDir & "\Folder2\Python.py") Or, if there is any potential you'll be changing the paths at some point, best practice would be to define them in your script first: Local $sPython = @ScriptDir & "\Folder1\Python.exe" Local $sPyScript = @ScriptDir & "\Folder2\Python.py" Then if you do have to change them, you only need to do so once. None of the above works :o,(i took a slow mo video and it says "the file path cannot be specified") the only time it will work is when the py file is in the same folder as the autoit file. What am i missing here? Edit: How about the _RunDos command? I think that would work, but I'm confused on the correct syntax in this example Edited September 14, 2016 by JustinM Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 15, 2016 Moderators Share Posted September 15, 2016 I just created the following folder structure: Top Level---Here resides my AutoIt Script Second Level "Test1" ---Here resides Python.exe Third Level "Test2" ---Here resides the python script. With the structure above, this code is working just fine for me: Local $sPython = @ScriptDir & "\Test1\Python.exe" Local $sPyFile = @ScriptDir & "\Test1\Test2\MyScript.py" ShellExecute($sPython, $sPyFile) As is this: Local $sPython = @ScriptDir & "\Test1\Python.exe" Local $sPyFile = @ScriptDir & "\Test1\Test2\MyScript.py" Run($sPython & " " & $sPyFile) So if it is not working for you, it has to be in your syntax, or in the python code. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
JustinM Posted September 15, 2016 Author Share Posted September 15, 2016 13 hours ago, JLogan3o13 said: I just created the following folder structure: Top Level---Here resides my AutoIt Script Second Level "Test1" ---Here resides Python.exe Third Level "Test2" ---Here resides the python script. With the structure above, this code is working just fine for me: Local $sPython = @ScriptDir & "\Test1\Python.exe" Local $sPyFile = @ScriptDir & "\Test1\Test2\MyScript.py" ShellExecute($sPython, $sPyFile) As is this: Local $sPython = @ScriptDir & "\Test1\Python.exe" Local $sPyFile = @ScriptDir & "\Test1\Test2\MyScript.py" Run($sPython & " " & $sPyFile) So if it is not working for you, it has to be in your syntax, or in the python code. I copied and pasted your exact code and it does the same thing. Here is a copy of my python code #!/usr/bin/env python # coding=utf-8 import heaven_automation import ctypes import math user32 = ctypes.windll.user32 user32.SetProcessDPIAware() [w, h] = [user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)] # set number of hours here hours = 1 iteration_number = int(math.floor((hours * 60 * 60) / 275)) # each benchmark loop is 4m 35 seconds approx. print iteration_number for i in range(iteration_number): heaven_automation.run(api='DX11', fullscreen=1, aa=8, width=w, height=h, quality='ultra', tessellation='extreme', log='%s_hours_loop.csv' % hours, log_caption='FPS,Score,API,Resolution,AA,Quality,Tessellation,GPU,CPU', log_format='$F,$S,$A,$v,$m,$quality,$tessellation,$g,$c') Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 15, 2016 Moderators Share Posted September 15, 2016 Try a simple python script, something like this: os.system("start /wait cmd /k {ping 127.0.0.1}") If that works, then the problem lies in your python script. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
JustinM Posted September 15, 2016 Author Share Posted September 15, 2016 (edited) 7 minutes ago, JLogan3o13 said: Try a simple python script, something like this: os.system("start /wait cmd /k {ping 127.0.0.1}") If that works, then the problem lies in your python script. Ok, that works, my autoit script opens this ping test just fine...now the question is what in my python code does not allow itself to be called from a different dir >.< Edit: My autoit script will call my python script just fine if they are both in the same folder, but i don't want that Edited September 15, 2016 by JustinM Link to comment Share on other sites More sharing options...
JustinM Posted September 15, 2016 Author Share Posted September 15, 2016 I believe I got it working by adding this code to the python script import os curr_dir = os.path.dirname(os.path.abspath(__file__)) os.chdir(curr_dir) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now