python替代批处理:打开IDEA等工程
易错点:
不能所用下图所示的反反斜杠(转义符)。如果用sublime Text 是会用下图所示的橙色提示的。
打开IDEA源码如下:
# -*- coding: utf-8 -*-
import os
Res = os.system('"D:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2019.3.1/bin/idea64.exe" ./') #只能用正斜杠
if Res == 1: # when 1,open failed, when 0, open success.
print("Open failed then try other path.\r\n");
Res = os.system('"C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2019.3.1/bin/idea64.exe" ./')
if Res == 1:
print("Error: Open failed!!!\r\n");
os.system("pause");
打开IAR工程如下:
# -*- coding: utf-8 -*-
import os
os.getcwd() #get current work direction.
os.chdir('Projects/ble/SimpleBLEPeripheral/CC2541DB') #change direction.
Res = os.system('"C:/Program Files (x86)/IAR Systems/Embedded Workbench 6.4/common/bin/IarIdePm.exe" SimpleBLEPeripheral.eww') #只能用正斜杠
if Res == 1: # when 1,open failed, when 0, open success.
print("Error: Open failed!!!\r\n");
os.system("pause");