在命令行里运行脚本,然后带参数,用python.exe -test.py -c ** -f ** or python.exe -test.py -h,这样能在cmd里面有print输出。但是用pyinstaller打包生成.exe后(pyinstaller -w -F test.py common.py),命令行能正常执行,但是没有print输出,求解
import sys
import common
if len(sys.argv) == 1:
valueforc = "None"
valueforf = "None"
print (valueforc,valueforf)
else:
(optc, valueforc, optf, valueforf) = common.command(sys.argv[1:])
print ("test1")
def command(argv):
try:
opts, args = getopt.getopt(argv, "hc:f:")
print(opts, args)
except getopt.GetoptError:
print('use the current options: test.py -c <categoryname> -f <featurename>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('test.py -c <categoryname> -f <featurename>')
sys.exit()
elif opt == "-c":
category = arg
optc = opt
optf = "None"
feature = "None"
elif opt == "-f":
feature = arg
optf = opt
optc = "None"
category = "None"
return(optc, category, optf, feature)