I’m new to Python and I have written a few python selenium tests. In my main file I have used the main.py to run all my selenium tests by using the import os module. I can execute the main.py through pycharm and python interpretar successfully but I can’t get it to work when trying to set up a schedule in Windows Tasks scheduler.
This is the error I’m getting
“The system cannot execute the specified program”
Any help would be appreciated. Thanks
In my main.py file I have
Import os
os.system (“python C:/Users/………filename.py”)
os.system (“python C:/Users/………filename2.py”)
Related
I'm new to Azure automation, and have a python script that runs fine on the local machine. The script runs a PowerShell command to get sign in logs, and does some string parsing on them before writing to a storage account table. I was able to install all dependencies for the script via the "Python Packages" blade in the automation account. Is there a way to add powershell.exe somewhere so that the subprocess library can be used to run the PowerShell command? Alternatively, is there a library you can import to be able to run the PowerShell command or grab sign in logs from Azure AD without directly using the powershell.exe file?
Also, Microsoft.Powershell.Core is added in the Modules within the automation account. Am I just using the wrong filename and should use something other than powershell.exe? Is there a different module you have to install, or am I referencing it wrong?
Here is the relevant portion of the script:
import subprocess
import sys
import json
import azure.core
from azure.core.credentials import AzureNamedKeyCredential
from azure.data.tables import TableServiceClient, TableClient
data = subprocess.check_output(["powershell.exe", "Connect-AzureAD -AccountId placeholder#placeholder.com \n Get-AzureADAuditSignInLogs"]).decode(sys.stdout.encoding)
This throws a "FileNotFound" error for powershell.exe. In the context of an Azure Automation runbook, how can you run powershell commands with the subprocess library, then? Any ideas are much appreciated. Many thanks
I have tested in my environment
I get the same error as yours if I use subprocess in my python script to run PowerShell command
This is because the subprocess module is not able to find the powershell.exe path
For the workaround, you can use either of the options:
You can use PowerShell script instead of python script
You can use MS Graph API in your python code instead of PowerShell commands
I have a python app that sends a notification whenever a specified YouTube channel gains a subscriber. I would like to have this run in the background instead of in terminal. Is there a way to do this? Here are my libaries if they could cause an issue:
import os
import urllib.request
import json
import time
from sys import platform
from plyer import notification
import subprocess
You can run your Python app as a service.
If you are using Windows you need some libraries such as:
win32serviceutil
win32service
win32event
servicemanager
In case of your Operating System is Windows, you can use .pyw file extension and then run the app, it will run in the background, you could only stop it using the Task Manager.
On Linux, the easiest solution is to add & at the end of the command.
I. e: python3 file.py &.
But it will not be started every time you start up the computer, you can use tools such as systemd for example, to automatically run it every time.
I want to run sikulixIDE-1.1.3 generated script through Python IDLE but don't know how to add in Python script.
I have generated file sikuli_script.sikuli using sikuliXIDE-1.1.3.
Through Python IDLE, I opened application but the next step is I want to call this sikuli script but don't know the way to add it.
from pywinauto.application import Application
>>> app = Application().start(r"C:/Program Files/Keysight/ADS2020/bin/ads.exe")
import os
>>> os.popen('python C:/Users/aakotkar/Desktop/Agile/GUI_Automation/Sikuli_script.sikuli/Sikuli_script.py')
<os._wrap_close object at 0x000001D32063F780>
It should run sikuli script but I know I am calling in wrong way. Any help?
I have a python script named update.py, and I want to use another python script to check whether the script is running or not. If update.py doesn't run or error, then the script will run update.py.
Can i do it? If there is an example it will be very thankful.
Not sure about what you are asking but as given this may help, so if you just want to call one python script from another then you can use script 1
#!/usr/bin/python
from subprocess import call
call(["python", "update.py"])
Save this file in a script named script1 and run it, it will compile update.py.
If you want to check for any syntax error in update.py then you can use script 2
#!/usr/bin/python
from subprocess import call
call(["python","-m","py_compile", "update.py"])
If script2 compiles without any error then it shows that there is no syntax error in your program.
Thirdly if you want to check if update.py is running currently or not you can use script 3
#!/usr/bin/python
import psutil
import sys
from subprocess import Popen
for process in psutil.process_iter():
if process.cmdline() == ['python', 'update.py']:
sys.exit('Process found: exiting.')
print('Process not found: starting it.')
Popen(['python', 'update.py'])
This last script will tell if your script is running or not and if it is not running it will compile it.
Scripts are generally used for these kinds of tasks. You have a monitor script that keeps track of update.py that keeps running in the background. It becomes easier if monitor script launches the python script in the beginning.
#!/bin/bash
# Monitor script.
EXEC=<path>/update.py
while true; do
"$EXEC" &
wait # Here the assumption is that you want to run this forever.
done
I'm using the app QPython, and while it's easy to run scripts from a file, I'm struggling to see how to load a script into the Console so that I can use it there (e.g. to use functions defined in a script).
I'm not very familiar with Python, so I don't know whether I'm having difficulty with Python or with the app. As far as I know in ordinary Python, the command "import script" will import all of the code in the file script.py, which has to be contained in the directory you loaded Python from (this is already concerning as I can't change the directory in QPython).
For the record, the equivalent command in Haskell (which I am familiar with) would be :l script.hs
To import some functions :
from script import functiona, functionb()
To import all functions from a script use :
from script import *
You could just do :
import script
But then you'll have to call your functions like that :
script.myfunction()