lately I had an idea to create an API with FastAPI where it would create services on windows. Do you think it’s possible or complete madness? I didn’t find any article talking about
I tried to create the following code, but without success
from fastapi import FastAPI, File, UploadFile
from fastapi.responses import JSONResponse
import subprocess
import os
app = FastAPI()
@app.post("/run_services/")
async def runservices(file: UploadFile = File(...)):
if file.filename.endswith(".msi"):
file_path = os.path.join(os.getcwd(), file.filename)
with open(file_path, "wb") as msi_file:
msi_file.write(await file.read())
install_command = f'msiexec /i "{file_path}" /quiet /qn /norestart'
process = subprocess.Popen(['powershell.exe', install_command], stdout=subprocess.PIPE)
process.communicate()
os.remove(file_path)
return JSONResponse(status_code=200, content={"message": "ok!"})
else:
return JSONResponse(status_code=400, content={"error": "problem"})
New contributor
Felipe Castro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.