在 Windows 的 bat 脚本中写 python 代码
"python" "%~dp0%~nx0"
exit
"""
字符串对于 cmd 来说是外部命令或参数,对于 python 来说是可拼接的字面量。
exit 对 cmd 来说是退出,对于 python 来说是一个函数名。
exit 会中止调用者,但在桌面点击运行的环境下可以正常使用。
"""
import uuid
import subprocess
def main():
while (input('Hit enter to generate another key: ').strip() == ''):
s = str(uuid.uuid4())
subprocess.run("clip", text=True, input=s)
print(f'{s} is sent to your clipboard!\n')
if __name__ == '__main__':
try:
main()
except:
pass
input('\nYou entered something else. Program will end after your next input.')