The book instructs us to run the assembler by supplying the name of the input file to it as a command line argument, thus:
prompt> Assembler Prog.asm
I'm able to write a program in Python which loads a text file containing assembly, translates it into machine code, and writes the result to a text file. I do this by supplying the name of the input file and the name of the output file in the Python code itself. So translating different text files requires me to modify those lines of the Python code.
I'm just not sure how to get the Python program to run from the command line, with the name of the input file supplied as an argument, rather than specified in the Python program itself. I assume this is a general question about command line, rather than about the Hack platform, but I wasn't able to find an answer online. Could you direct me to an appropriate resource?
Thanks for your quick and helpful reply. I'm still a bit confused. I hope my question is not taking us too far afield. In case it's relevant, I'm using the Enthought Canopy (64-bit) distribution on an Asus Zenbook running Windows 10.
I've added ".py" to the PATHEXT environment variable and the directory containing my python programs (namely, "C:\Users\Cosmo\Desktop\nand2tetris\nand2tetris\projects\06") to the Path environment variable. But things aren't behaving as I'd like.
print 'hello world'
In the command prompt, I get the following results (where the current directory is not the directory containing hello.py) :
This opens the file hello.py in Canopy, but doesn't execute it.
> python hello
python: can't open file 'hello': [Errno 2] No such file or directory
> python C:\Users\Cosmo\Desktop\nand2tetris\nand2tetris\projects\06\hello
python: can't open file 'C:\Users\Cosmo\Desktop\nand2tetris\nand2tetris\projects\06\hello': [Errno 2] No such file or directory
> python C:\Users\Cosmo\Desktop\nand2tetris\nand2tetris\projects\06\hello.py
So when I don't put "python" at the start, it knows to look in the right directory to find hello.py, and it doesn't need the file extension; but it just opens the file, rather than executing it. When I do put "python" at the start, I have to give it the full path and the file extension of hello.py. What I'd like to do is get: