Ethan Dalool
8d4e353c66
If the command is an executable, you can have quotes around it. But if it is a builtin like `copy` then quotes will break it. So let's remove quotes from the command as long as it doesn't have spaces. Also remove quotes from & and && because with quotes you can't actually chain commands. However if you want to literally use & as an arg then this may cause some problems.
32 lines
805 B
Python
32 lines
805 B
Python
'''
|
|
Create a task file to be executed by do_tasks.
|
|
|
|
Usage:
|
|
taskme command arg1 arg2
|
|
'''
|
|
import sys
|
|
import time
|
|
import random
|
|
import os
|
|
|
|
if len(sys.argv) < 2:
|
|
raise ValueError()
|
|
|
|
task_line = sys.argv[1:]
|
|
task_command = task_line[0]
|
|
if ' ' in task_command:
|
|
task_command = '"%s"' % task_command
|
|
task_arguments = task_line[1:]
|
|
for (index, arg) in enumerate(task_arguments):
|
|
if arg not in ['&', '&&']:
|
|
task_arguments[index] = '"%s"' % arg
|
|
task_arguments = ' '.join(task_arguments)
|
|
|
|
task_command = f'cd /d "{os.getcwd()}" & {task_command} {task_arguments}'
|
|
|
|
timestamp = f'{time.time():<019}'.replace('.', '')
|
|
randid = f'{random.randint(1, 1000000):>06}'
|
|
filename = f'C:\\tasks\\{timestamp}-{randid}.task'
|
|
|
|
with open(filename, 'w', encoding='utf-8') as handle:
|
|
handle.write(task_command)
|