import subprocess
def run_subprocess(command):
"""
Run a subprocess and return its output.
"""
try:
output = subprocess.check_output(command.split())
return output.decode('utf-8')
except subprocess.CalledProcessError as e:
return e.output.decode('utf-8')
def run_command(command):
"""
Run a command and return its output.
"""
try:
output = subprocess.check_output(command.split(), stderr=subprocess.STDOUT)
return output.decode('utf-8')
except subprocess.CalledProcessError as e:
return e.output.decode('utf-8')
def execute_command(command):
"""
Execute a command and capture its output.
"""
try:
output = subprocess.check_output(command.split())
return output.decode('utf-8')
except subprocess.CalledProcessError as e:
return e.output.decode('utf-8')
def execute_subprocess(command):
"""
Execute a subprocess and capture its output.
"""
try:
output = subprocess.check_output(command.split(), stderr=subprocess.STDOUT)
return output.decode('utf-8')
except subprocess.CalledProcessError as e:
return e.output.decode('utf-8')
def shell_command(command):
"""
Execute a command in the shell.
"""
try:
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
return output.decode('utf-8')
except subprocess.CalledProcessError as e:
return e.output.decode('utf-8')
def check_output(command):
"""
Execute a command and return its output.
"""
try:
output = subprocess.check_output(command.split())
return output.decode('utf-8')
except subprocess.CalledProcessError as e:
return e.output.decode('utf-8')
def shell_exec(command):
"""
Execute a command in the shell and return its output.
"""
try:
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
return output.decode('utf-8')
except subprocess.CalledProcessError as e:
return e.output.decode('utf-8')
def open_url(url):
"""
Open a URL in the default browser.
"""
import webbrowser
webbrowser.open(url)
def run_python(code):
"""
Run a Python script and return its output.
"""
try:
output = subprocess.check_output(code.encode('utf-8'), stderr=subprocess.STDOUT)
return output.decode('utf-8')
except subprocess.CalledProcessError as e:
return e.output.decode('utf-8')
def check_python_code(code):
"""
Run a Python script and check its output.
"""
try:
output = subprocess.check_output(code.encode('utf-8'), stderr=subprocess.STDOUT)
return output.decode('utf-8')
except subprocess.CalledProcessError as e:
return e.output.decode('utf-8')
def upload_file(file_path, url):
"""
Upload a file to a URL using POST request.
"""
import requests
file_name = file_path
with open(file_path, 'rb') as f:
files = {'file': (file_name, f)}
response = requests.post(url, files=files)
return response.text
def download_file(url, file_path):
"""
Download a file from a URL to a path using Python.
"""
import requests
response = requests.get(url, stream=True)
response.raw.decode_content = True
with open(file_path, 'wb') as f:
for chunk in response.iter_content(1024):
f.write(chunk)
return file_path
def get_file_content(file_path):
"""
Read the content of a file.
"""
with open(file_path, 'rb') as f:
return f.read()
领取专属 10元无门槛券
手把手带您无忧上云