andrewheiss / SublimeStataEnhanced

Plugin that adds support for Stata 11–15 for Sublime Text 2 and 3
56 stars 22 forks source link

Is this working for Stata 13 under Windows? #18

Closed 2sls closed 10 years ago

2sls commented 10 years ago

Is my understanding correct that the temporary do file solution works under Windows for Stata13?

I am seeing the sublime2do file created after I ctrl+enter, but it does not execute.

Anyone know what could be the problem?

I edited my windows sublime settings as { "stata_version": 13, "stata_name": "C:/Program Files (x86)/Stata13/StataMP-64.exe" }

andrewheiss commented 10 years ago

Yeah, the temporary do file thing should work for Stata 13 in Windows. The trickiest (and most fragile) part of the plugin is getting Windows to run the temporary file.

The way the plugin work is it creates a temporary .do file and a temporary .vbs file to run the .do file. The .vbs file gets deleted after it is run, but it looks like it's not running properly for you. To debug this, eidt text_2_stata.py and comment out line 129, (os.remove(vbs_path)). Then try to send a selection to Stata. You'll see two new files: sublime2stata.do and open_in_stata.vbs. Open the .vbs file and see what it looks like. It should look something like:

CreateObject("WScript.Shell").Run """path/to/stata.exe"" ""path/to/vbs/file""", 4, false 

With some number of quotes, that may or may not be escaped. Open the command line, navigate to the .vbs file with cd and then type cscript.exe open_in_stata.vbs to run the .vbs file. If it doesn't work, it should give you some hopefully useful error messages.

2sls commented 10 years ago

After editing out the removal in the python file and running the vbs script through DOS, the script executes in the sense that it will open a new Stata instance and run the contents of the sublime2stata.do file so I am at a lost why this doesn't happen inside Sublime.

Another note is that when I have an existing Stata 13 instance open, executing the vbs script in DOS will still create a new Stata instance rather than executing it within the existing instance.

andrewheiss commented 10 years ago

Ok, cool. That's a good sign.

The multiple instances of Stata opening is most likely related to the different arguments passed to the CreateObject().Run command (i.e. the 4 and the false). That command takes a bunch of different combinations of arguments, listed here. I unfortunately don't have Stata on Windows (I just have a VM with Windows), so I was testing the arguments with Notepad, which doesn't spawn multiple instances. Stata apparently does though. You can toy around with different options in the vbs script and see if any don't open new instances, then I can add that to the plugin.

Are there any errors in the ST console (View > Show Console) when you run the command? ST is apparently struggling to find run the vbs script—perhaps it gives some indication as to why…

2sls commented 10 years ago

OK... I figured out why it wasn't executing the VBS script. in text_2_stata.py, the cmd being executed is fragile with respect to vbs_path because it needs to be double quoted.

My hacked solution was vbs_path="\""+vbs_path+"\"" after line 125.

This allows for the vbs script to be executed.

The problem of sending the script to executed in the existing Stata instance remains because it will just keep on opening new instances with every command.

I took a look at the link you sent, and cycled through all of them but none of them allowed for execution within an existing instance.

andrewheiss commented 10 years ago

Cool. Change line 127 to cmd = "cscript.exe {0}".format("\""+vbs_path+"\"") and tell me if it still works. If so, I'll make the change official.

I wonder if there's some preference in Stata that allows or disallows multiple instances. Other people that helped me test this on Windows didn't have the same problem with new instances in each command, so it might be something specific to your computer, or specific to Stata 13…

2sls commented 10 years ago

Yes the change works.

I don't know... hoping some other users will chime in. I tried to search for such a setting but no luck

andrewheiss commented 10 years ago

I just fixed it. Can you open a separate issue for the multiple instance thing so other people can potentially see it?

Thanks!