0

I am running a python script file in which it should run a c++ executable file from another folder with some arguments.

The executable file is located in root home ubuntu i.e. (~/camera_intrinsic_calibration) folder

Generally I run on the terminal in that folder location as follows:

./pngCamCalStep1 /home/nvi/Perception/09-22-22/data/60_left/%04d.png 12 8 0.05

where ./pngcamcalstep1 is my c++ executable file and others are arguments needed to be passed.

Hence in the script file I tried the following using subprocess but none of them work:

result = subprocess.call(["./pngCamCalStep1", "home/nvi/Perception/sensor_0/left-%04d.png", "12" ,"8", "0.05"], check =True, capture_output=True, cwd='/home/nvi/camera_intrinsic_calibration/',shell =True)

or

result = subprocess.run(shlex.split("./pngCamCalStep1 home/nvi/Perception/sensor_0/left-%04d.png 12 8 0.05"), check =True, capture_output=True, cwd='/home/nvi/camera_intrinsic_calibration/', shell =True)

It doesn't work and I get output as :

Traceback (most recent call last):
  File "/home/nvi/catkin_ws/src/camera_calibration/src/camera_calibration/camera_calibrator.py", line 340, in on_mouse
    self.c.do_calibration()
  File "/home/nvi/catkin_ws/src/camera_calibration/src/camera_calibration/calibrator.py", line 1280, in do_calibration
    result = subprocess.call(["./pngCamCalStep1", "home/nvi/Perception/sensor_0/left-%04d.png", "12" ,"8", "0.05"], check =True, capture_output=True, cwd='/home/nvi/camera_intrinsic_calibration/',shell =True)
  File "/usr/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
TypeError: __init__() got an unexpected keyword argument 'check'

Can anyone please let me know how to solve this problem?

What is the right command to call or run a C++ executable file from another folder with providing it's input arguments?

2 Answers 2

2

Your syntax is mostly correct.

The error message is quite clear: subprocess.call(), which use subprocess.Popen class as backend, does not accept a keyword argument 'check'

Remove that argument and try again.

If you want CalledProcessError to be raised when the called process return non-zero returncodes, use subprocess.check_call() instead.

Sign up to request clarification or add additional context in comments.

Comments

0

Well, I have kept the whole argument in a single quote, then it worked, removing, check and capture_output:

subprocess.call(["./pngCamCalStep1 home/nvi/Perception/sensor_0/left-%04d.png 12 8 0.05"], cwd='/home/nvi/camera_intrinsic_calibration/',shell =True)

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
@ellhe-blaster I dont undertand how it is unclear when you have a crystal clear answer in front of you for what is the proper syntax. Your comment is not correct. Either let me know what is unclear so I can add more information or edit your comment. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.