Announcement

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

  • Problem with Stata not recognizing the hostname (OSX)

    Dear Statalisters,

    I manage my work in multiple computers with different paths for the same project. All my *.do files therefore start with a set of codes that identifies the machine by the 'hostname' and set the file location path accordingly, such as:

    Code:
    ****Start of a particular do file for one particular analytical project:**********
    ******************************************************************************************
    
        if "`c(hostname)'" == "Roms-MacBook-Pro.local" {
                cd "/Users/Rom"
                }
        if        "`c(hostname)'" == "Roms-iMac.local" {
                cd "/Users/rom/Desktop/bla...."
                }
        if  "`c(hostname)'" == "TZKC96058HTY" {
                cd "C:/Users/bpd/"
                }
        if  "`c(hostname)'" == "biosciences" {
                cd "/Users/rom87/"  
                }
    
    pwd
    The solution above was working fine for me for many years. All of a sudden since this morning my Stata is not recognizing the commands for my path locations. I then looked that the hostname:

    Code:
    di "`c(hostname)'"
    Roms-iMac
    You can see above that the ".local" extension disappeared from the 'hostname' which was there for many years (see the red colored hostnames in the first set of codes which were there for many years). This is consistent to the result I obtain using terminal if you type -hostname- in the terminal. However, it gets confusing when I go to my mac system preference->sharing, it says that "Computers on your local network can access your computer at "Roms-iMac.local" (the extension is there!). So far I understand from OSX documentions that OSX adds *.local extension automatically by default to whatever the hostname is supplied and that was being used in all my dofiles so far i.e., the system was being recognized as "Roms-iMac.local".


    Now while I am baffled and not sure what is causing the system not recognizing the extension of the hostname anymore even though it is there, one solution to my problem is to change the hostname in all my *.do files from "Roms-iMac.local" to "Roms-iMac"but that will require me to change all my *.do files and I will hate that.

    I wonder is there any other way to make Stata recognizing the hostname as "Roms-iMac.local" instead "Roms-iMac"? That will save me from changing all my *.do files.

    Thanks.




    System: iMac (late 2015)
    OSX: macOS Montrey (all updated as of today)
    Stata.version.17 (all updated as of today)


    Roman

  • #2
    The output of help creturn describes how to change c() values that are changeable; no such information is given for c(hostname).

    I note that, as you say, issuing the hostname command in the terminal does not include the .local suffix today, and this is true not only on my Mac running Monterey but also on an older Mac running Catalina, and since that is where we'd expect Stata to obtain the hostname, this suggests some sort of security patch by Apple at the level of the "Install system data files and security updates" in the Advanced Options panel of Software Update in System Preferences.

    I think you are going to have to make the changes. Can I suggest replacing your
    Code:
        if "`c(hostname)'" == "Roms-MacBook-Pro.local" {
                cd "/Users/Rom"
                }
        if "`c(hostname)'" == "Roms-iMac.local" {
                cd "/Users/rom/Desktop/bla...."
                }
        if  "`c(hostname)'" == "TZKC96058HTY" {
                cd "C:/Users/bpd/"
                }
        if  "`c(hostname)'" == "biosciences" {
                cd "/Users/rom87/"  
                }
    with
    Code:
        local hostname = c(hostname)
        local hostname : subinstr local hostname ".local" ""
        local cd_Roms-MacBook-Pro "/Users/Rom"
        local cd_Roms-iMac "/Users/rom/Desktop/bla...."
        local cd_TZKC96058HTY "C:/Users/bpd/"
        local cd_biosciences "/Users/rom87/"  
        cd "`cd_`hostname''"
    to make yourself more robust to the possible reappearance of the .local?

    Comment


    • #3
      That is probably the best advice William. Thank you.
      Roman

      Comment

      Working...
      X