'How to error handling curl and mysql in python subprocess.run()

I have python script which uses subprocess.run()

getting dump file by curl and input dump file by 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)

For now, it works well, however it doesn't have any error handling.

  • If curl fails I would to show the message and prevent from exec mysql
  • If mysql fails, I would like to show the message.

What is the best practice for this purpose?



Solution 1:[1]

SqlCommand com = new SqlCommand("YourDBName", objconn.con);
            com.CommandType = CommandType.StoredProcedure;
            com.Parameters.AddWithValue("@ErrorID", 00);
            com.Parameters.AddWithValue("@ErrorDiscription", "InValid");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thaveshan Naidoo