0

I was wondering if you could help me with my new python program. I recently added a browse button to the GUI to make things more "user-friendly." I told python to only accept *.pvt files when the user is asked to browse for a file... Now, I am left wondering how to tell python to take the path the user browsed to and open a cmd window[using subprocess.Popen("cmd.exe")] and cd to that user defined path.. any ideas???

here's what i have so far...

 def OnAbout3(self, event): """ Browse for file """ wildcard = "Select File (*.pvt)|*.pvt" dialog = wx.FileDialog(None, "Choose a file", wildcard=wildcard, style=wx.OPEN) if dialog.ShowModal() == wx.ID_OK: path = dialog.GetPaths() #######this is where i wanted to do something like this: subprocess.Popen("cmd.exe") #I wished cmd could simply cd to the variable, path os.system('cd path') dialog.Destroy() 

so, obviously, this doesn't cd to path. how can i do this??

1
  • 1
    How about cmd.exe /k cd path? Commented Jun 3, 2011 at 13:43

1 Answer 1

4

Did you try this:

subprocess.Popen('cmd.exe', cwd=path) 

This is based on the assumption, that you don't really want to cd, but instead want the current working directory to be set - which is the post condition of cd...

Check the subprocess module for more awesome parameters and examples!

Sign up to request clarification or add additional context in comments.

6 Comments

it didn't work.. i got an error using this code.. "must be string, not list."
@user715578: use dialog.GetPath(), not .GetPaths(). You're not allowing multiple selections anyway, and you want 1 path, not a list of files.
it says directory name is invalid.. :(
could you print the directory name to the console before starting cmd.exe? let's show some of your debugging skillz here!
I'm sorry.... I just started python not too long ago and I am lost.. how would I go about doing so?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.