Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to run Linux commands (using Stata's shell command) on a Windows machine?

    Hello all,

    I am running Stata 13.1 on a Windows 7 machine.

    I have a project with lots of existing code written for a Linux environment. Unfortunately, at present I must use a Windows environment.

    One line of the Linux code is written below. Is there a way to get this command to run from within Stata on a Windows machine?

    !zcat /dir1/dir2/testfile.zip | cut –d , -f 2,5,13-83 > testfile.txt

    This command cuts specific columns from a zip file and then saves only those columns to a text file.

    Of course, the “zcat” utility is not available for Windows.

    One option for solving my problem would be to find a way to accomplish the above Linux command with Windows and Stata code. However, this would require re-writing all the existing Linux code, so it would be preferable to get the Linux commands to run with Stata in Windows.

    Here is what I’ve tried so far:
    1. Installed Cygwin; attempted to integrate Cygwin with windows command prompt. Basic Linux commands would work correctly (ls, cd, pwd, etc), but zcat (and others) would not. This may be due to incompatibilities between Cygwin and command prompt on a 64-bit machine, or maybe an issue with system paths that I’m not familiar with. In any case, I have not been able to get this to work correctly. If I did get Linux commands to run from command prompt via Cygwin, I think I would be able to leave the code written for Linux as-is by using Stata’s shell command followed by the original Linux code.
    2. Attempted to run Stata from within Cygwin. Apparently this is possible, but I have not been able to find any tutorials via google. It may simply be that I do not know the correct search terms. I believe this method of running Stata is referred to as “batch mode”, but so far I have not been able to get Stata to run at all from within Cygwin. Maybe I’m simply writing the code to get this started incorrectly?
    If anyone has experience with running Linux commands in conjunction with Stata for use in Windows, I would very much appreciate your advice on how to proceed.

    Many thanks,
    Nicolas
    Last edited by Nicolas Swagar; 10 Mar 2015, 14:13.

  • #2
    Certain commands (ls, pwd) work since they're not actually using Linix, but have been integrated into Stata. I don't think you'll have much luck with the approaches you describe, least of all running it from Cygwin, since you would currently be attempting to run Windows Stata from a Linix-like environment. The shell command (as far as I know) only accepts one command at a time, so you might use it to bring up Cygwin from within Stata, but then it's stuck and further commands go to the regular Windoes shell.

    If you have access to the installation packages for Stata, and a reasonable amount of hard drive space and memory, it seems to me that the simplest might be to use a "Live DVD" or "Live CD" to boot into a full Linux environment. Ubuntu is a very complete Live DVD; Puppy is a popular lightweight one (though I dunno if Puppy can run Stata). In any case, you can dedicate a chunk of your hard drive for usage by the Live CD/DVD, and install Linux-flavor Stata there. Might sound complicated, but when I've tried it for various tasks (not running Stata, though), it wasn't bad. License-wise you should be fine -- it's still you, running your own copy of Stata. If you're in a shared environment without installation media, then clearly it's not going to work.

    Another approach would be VirtualBox (https://www.virtualbox.org/); install Linux into that and then install Linux-flavored Stata in turn. This could be nice, since you can stay in Windows for most things, and just fire up the virtual machine for running your Stata files that need it.

    Comment


    • #3
      Thanks for your reply, Ben.

      I realize what makes most sense is to simply use Linux. Unfortunately, for the current project I am unable to use Linux, so using a VM or Live CD/DVD/USB is not an option.

      I was hoping that someone out there had run into a similar problem before, i.e., utilizing Linux commands on a Windows machine.

      Comment


      • #4
        You can use python. Run .py file from Stata’s shell command is straightforward. I use it to deal with big data, for example, iterating through file chuck and HDF. And of course, you can run Stata from windows command line. It’s just like you run python from windows command line.

        Here is an example. I need to list file name in one directory. But there are too many files. So Stata's macro cannot store the list. I call python from Stata.
        Code:
        cd "C:\python34"
        shell python list_of_file_name.py
        And list_of_file_name.py contains the python code.
        All done beautifully.
        Last edited by Jimmy Yang; 15 Jul 2015, 20:08.

        Comment

        Working...
        X