我有使用 subprocess.run() 的 python 脚本
通过 curl
获取转储文件并通过 mysql
输入转储文件
cmd = "curl {0}/{1} -o /tmp/{2}".format(dir_name,file_name,file_name)
subprocess.run(cmd,shell=True)
cmd = "mysql -h main-rds.sfsadsafasdad.ap-northeast-1.rds.amazonaws.com -u admin -pXXXXXXXXXXXXXX mydbname < /tmp/{0}".format(file_name)
subprocess.run(cmd,shell=True)
print(cmd)
目前,它运行良好,但没有任何错误处理。
- 如果
curl
失败,我会显示消息并阻止执行mysql
- 如果
mysql
失败,我想显示消息。
为此目的的最佳做法是什么?
回答1
SqlCommand com = new SqlCommand("YourDBName", objconn.con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@ErrorID", 00);
com.Parameters.AddWithValue("@ErrorDiscription", "InValid");