I need to launch a program within a python script that has an argument.
Code is:
from datetime import date, timedelta
import os
yesterday = (date.today() - timedelta(days=1)).strftime('%m%d%y')
os.system('"E:/Bootdrv/AlohaTs/Bin/grind.exe /yesterday"')
Any help?
for calling a program with python i use subprocess lib
https://docs.python.org/3/library/subprocess.html
from subprocess import call
call("service camera restart")
this restart a linux service
Related
I'm a bit turned around on how to execute a shell script file in a Linux environment via Python's subprocess command in Streamlit. Any assistance on what I'm missing is appreciated.
I'm using a shell script called 0_texts.sh to run Pylanguagetool for a grammar check of one text file and return corrections in another text file, like so:
cd /home/user/dir/TXTs/
pylanguagetool text_0.txt > comments_0.txt
This script runs correctly in the Linux terminal, writing a comments_0.txt with appropriate grammar checks from text_0.txt.
I need to create a Python/Streamlit app that runs these shell scripts. In attempting to run this shell script, I've written script.py below:
import os
import subprocess
import sys
subprocess.run(['bash','/home/user/dir/Scripts/0_texts.sh'])
I then run script.py in Streamlit via the code below, keeping with Streamlit's documentation on using subprocess here.
import streamlit as st
import os
import subprocess
import sys
def app():
button1 = st.button("Click me")
if button1:
p = subprocess.run([f"{sys.executable}", "/home/user/dir/pages/script.py"])
st.write(p)
When I execute the script.py via Streamlit, the 0_txts.sh script executes, writing comments_0.txt in the correct directory and providing the following traceback: CompletedProcess(args=['/usr/bin/python3', '/home/user/dir/pages/script.py'], returncode=0). However, the comments_0.txt output contains the error input file is required, as if it can't properly access or read text_0.txt. I've tinkered around trying to find the problem, but have hit a brick wall.
Any suggestions on what I'm missing, or paths forward? Any help greatly appreciated.
I created a Python script that uses the Todoist API to export my task list to a list of strings (I want to paste them as Discord messages) and it works fine if I run the command on the Terminal window, but if I run the same command using AppleScript, an error is thrown, saying No module named todoist.api.
Here's the code: (I have only one line)
do shell script "$HOME/tasks.sh"
The shell scripts runs the python scripts I need, but the problem is in the imports of those files, which are:
from datetime import date, datetime, timedelta
from todoist.api import TodoistAPI
import pyperclip
import os
import MyTodoist
in the first file (tasks.py) and
from datetime import date, datetime, timedelta
from todoist.api import TodoistAPI
import pyperclip
import os
in the second file (MyTodoist.py)
The final goal is to store the result of a function in tasks.py in a variable in my script, but I don't know how. Can someone help me please?
I'm trying to invoke a vbscript through python as follows
import os
import sys
import pandas as pd
import numpy as np
rancsv = pd.DataFrame(np.random.randn(150, 5))
rancsv.to_csv('randomcsv.csv', sep=',')
os.system(r"C:\Users\v-2mo\Documents\Python Scripts\test.vbs")
However this simply gives an output of 1 in jupyter notebook and does not run the script.
The script when run directly, runs just fine.
What am I doing wrong?
os.system(r"C:\\Users\\v-2mo\\Documents\\Python Scripts\\test.vbs")
or
os.system(r"C:/Users/v-2mo/Documents/Python Scripts/test.vbs")
answered well here https://stackoverflow.com/a/19114284/17889328
in short, .vbs opens ok in command prompt because shell associates with program wscriipt or cscript and runs it. run silently your program doesn't get the associationand doesn't know how to open. need specify "wscript filename.vbs" and / or run with shell eg "cmd /c..."
I have following code as custom python script:
#!/usr/bin/env python
import sys
import re
from sys import stdin
sys.stdout.write(DOC_FILENAME)
How can I use this as custom command in Geany to get current document name and path ?
Is "geanypy" needed to be installed to run this command ?
I want to launch a shortcut named blender.ink located at "D://games//blender.ink". I have tryed using:-
os.startfile ("D://games//blender.ink")
But it failed, it only launches exe files.
The Python os.startfile function should work fine, but you need to specify a .lnk extension to be a valid Windows shortcut file:
import os
os.startfile (r"D:\games\blender.lnk")
If you need to wait for the application to complete before continuing, then a different approach would be needed as follows:
import win32com.shell.shell as shell
import win32event
se_ret = shell.ShellExecuteEx(fMask=0x140, lpFile=r"D:\games\blender.lnk", nShow=1)
win32event.WaitForSingleObject(se_ret['hProcess'], -1)