Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

run powershell script in python

You can do this simpily by doing the following:
  
import os

os.cmd('powershell commands/args here')


  ===============================================
  |		   Simple proccess kill script:			|
  ===============================================

# Not a default module: install by doing: 'pip instal psutil'
# or by doing: 'py -m pip install psutil'
import psutil
import os

process = ["Skype.exe"] 
# When adding other proccess to this list, Please add copy the name to the tee
# Other wise it will not find it

while True: # We keep this going forever (You can remove the True loop)
    for procs in process: # We then get the items from the table above
        if procs in (p.name() for p in psutil.process_iter()): # Check for them
            os.system(f'powershell TASKKILL /F /IM {procs}')
            # If the exes from the table is running then we force kill the proc
            # Using powershell (doesnt have to be ps can be just normal CMD)
            # The kill command will print the proccess it killed and the PID
    time.sleep(4) # After, We will then wait 4 seconds before looping again
Comment

run powershell script python

import subprocess, sys

p = subprocess.Popen(["powershell.exe", 
              "C:ProjectdownloadSharePointFile.ps1"], 
              stdout=sys.stdout)
p.communicate()
Comment

PREVIOUS NEXT
Code Example
Python :: dataframe to list pyspark 
Python :: python sqlite 
Python :: list tuples and dictionary in python 
Python :: elif in django template 
Python :: convert array to set python 
Python :: convert price to float python 
Python :: clamp number in python 
Python :: tf-idf python implementation 
Python :: loop through a column in pandas 
Python :: list of numbers 
Python :: python remove special characters from list 
Python :: two for loops in list comprehension 
Python :: conda python update 
Python :: python find intersection of two lists 
Python :: chrome driver in python selenium not working 
Python :: django date formatting 
Python :: Write a Python program to get the Python version you are using. 
Python :: tkinter margin 
Python :: pip install streamlit 
Python :: pip install qrcode python 
Python :: limit for loop python 
Python :: python summary() 
Python :: print last exceuted query python 
Python :: day name in python 
Python :: python f string 
Python :: how to make a latency command in discord py 
Python :: how to display percentage in pandas crosstab 
Python :: how to use turtle in python in python 3.9 
Python :: get absolute url django 
Python :: python subprocess print stdout while process running 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =