How to execute a saved script in command line?


#1

Please leave the following link in the post so we can find the unit module, else replace it with a link to the exact lesson:

Strings and Console Output


#2

you can type: python scriptname.py, where scriptname is the name of your script, and you are in the same directory.


#3

what if the script is in a different directory, is there a direct command


#4

then you have to do path\to\scriptname.py where path\to is an absolute or relative path to the script.

if you use *nix based system, the path should use forward slashes, backward slashes is for windows


#5

can you give an example, for windows, what exactly to type. suppose the script is in d drive


#6

you first need to navigate to d:, CMD opens in C: by default, so scripts would be easier to have on the c drive.

you first need to switch to D drive:

d:

then from there you could do:

scriptname.py

assuming d: lands you in the right directory, this depends what on the D: drive. I moved my home directory there, so for me, it opened D:\myuser where myuser is my name, which i am not going to share. Not sure why windows put me there and not in in D:\

is the script in D without any subfolders? then it would be:

d:
cd \
python scriptname.py

#7

in cmd, it is not working. it says that python is not a recognizable command. are we talking about the command line, that comes with the software? i am using windows and python 2.7


#8

python needs to be installed of course, and inside PATH for cmd to find it.

it could be that the command is python2, press tab twice to see auto complete options


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.