I am learning to program in python through the book "Learn python the hard way". Therefore I use powershell to run my programs. Since I had to manually change the directory every-time I started powershell , I wrote a batch file to automate it.

The command I wrote is :

powershell.exe -noexit -command "'cd c:\self\pooja\"edu n career"\programs\python'"

The problem is that it runs but opens the directory of "programs" only. Why is it not changing to python directory?

Finally , I did it by setting the "Start in" field in the shortcut property of powershell but I want to know why the batch file is not working as expected.


Close Nate, but that doesn't work when I run it on a "New Folder". Had to move the CD outside the single quotes to make it work.

powershell.exe -noexit -command "cd 'c:\New folder'"
powershell.exe -noexit -command "cd 'c:\self\pooja\edu n career\programs\python'"
  • I am trying to run the batch file again but cmd starts and closes immediately . I have written it same as you told. – Pooja Jan 15 '18 at 17:52

I'm not quite sure what your directory folder looks like, but assuming that edu n career is one directory, you shouldn't need to escape that with its own set of double quotes, you should be able to change the code to

powershell.exe -noexit -command "'cd c:\self\pooja\edu n career\programs\python'"

If you look at the command in a text editor with syntax highlighting, you can see that the edu n career is actually not part of the command.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.