atom-community / atom-script

:runner: Run ( scripts | selections | source ) in Atom
https://atom.io/packages/script
MIT License
733 stars 269 forks source link

[Win10] Can't change current working directory if atom is not started using 'atom .' command. #1025

Open goddessfreya opened 8 years ago

goddessfreya commented 8 years ago

Recently I was struggling with changing the working directory of my python program. If 'Current Working Directory' was not empty, trying to run would give an error when trying to be run.

Dependencies: Python 3.5.2

Steps: 1- Insure no other copy of atom is running 2- Open Atom through the shortcut which appears in the Start Menu. (Target: %AppData%..\Local\atom\Update.exe --processStart atom.exe Start In: %AppData%..\Local\atom\app-1.9.1) 3- Press Ctrl-N then type "print("Hi")" into the new file 4- Press Ctrl-S then save it somewhere. 5- Press Ctrl-Shift-B, insure it runs. 6- Press Alt-Ctrl-Shift-O 7- Under 'Current Working Directory' type the relative path to a other directory, in my case that was 'data' 8- Press run. You will get something like this this:

Unable to run

python

Did you start Atom from the command line?

atom .

Is it in your PATH?

PATH: C:\Python35-32\Scripts\;C:\Python35-32\;C:\tools\ruby23\bin;%Path2%;C:\Projects\Dev\Tools\CMake\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\TortoiseGit\bin;C:\Projects\Dev\Tools\Chocolatey\bin;C:\Program Files\nodejs\;C:\Program Files\Git;C:\Program Files\Git\bin;C:\Users\Gentz.dnx\bin;C:\Users\Gentz\AppData\Roaming\npm;C:\Users\Gentz\AppData\Local\atom\bin;C:\Python2.7;C:\Python27;C:\Python3.4;C:\Python34;C:\Python3.5;C:\Python35;C:\Program Files (x86)\Python 2.7;C:\Program Files (x86)\Python 3.4;C:\Program Files (x86)\Python 3.5;C:\Program Files (x64)\Python 2.7;C:\Program Files (x64)\Python 3.4;C:\Program Files (x64)\Python 3.5;C:\Program Files\Python 2.7;C:\Program Files\Python 3.4;C:\Program Files\Python 3.5

How to fix it: 1- Close all instances of atom 2- Open cmd.exe with elevated permissions. 3- Type 'cd [diorectory where you saved the thing]' then hit enter then type "atom ." then hit enter 4- Open the file you saved 5- Press Ctrl-Shift-B, insure it runs. 6- Press Alt-Ctrl-Shift-O 7- Under 'Current Working Directory' type the relative path to a other directory, in my case that was 'data' 8- Press run, now it will work.

goddessfreya commented 8 years ago

I must also add, before I used the temporary fix, os.chdir() wouldn't change the current working directory and would quietly do nothing. After doing my fix os.chdir() changes the directory even when I start Atom through the shortcut (instead of through command prompt). Sadly to use the 'Current Working Directory' setting I still need to start Atom through command prompt.