Search code examples
pythoncmdexecution

what is meaning of this python call


I have an example of Python script script.py, which is supposed to take a binary file and convert it to another binary file. In the example, the call is as follows:

dir1/file1 -D python dir2/file2 > script.py

I thought it will take file2 from dir2, convert and output is as file1 in dir but it is not the case. When I run this script (I ensured the dir2/file2 exists) nothing happens.

Inside the script.py I have the code:

def main():
    if len(sys.argv) <2:
        print >>sys.stderr
        sys.exit(1)
    try:
        convert(sys.argv[1])
    except: return1

So I assume that the main work is done by some other function convert. What puzzles me is the cmd call for this script. How to interpret this call?
Is this normal way of calling python functions?

Edit after comments: Thanks for explanation, the file1 is a binary and it exists on the system. Originally I thought it was created by the script by someone who already did it. From what you say it looks that it is some kind of executable which calls python in the background.

(By the way it is interesting how people downgrade the question if they don't know the answer)


Solution

    • Is it normal: The normal way to call python scripts is: python script_name.py ARGS, so if what you pasted is made intentionally, it is not normal.

    • How to interpret the CMD call: The thing you added is running file1 with the arguments -D python dir2/file2 and then redirecting STDOUT to script.py So to gain any insight you need to know what file1 is. Try file --help or file --h, if that does not help, try opening it with hexdump or run strings file1 which will show the literal strings present in the file. They might give you an insight.