Write a copy of the current script

Discussion in 'Ruby' started by dkmd_nielsen, Feb 18, 2008.

  1. dkmd_nielsen

    dkmd_nielsen Guest

    I would like to write a copy of the current script being executed.
    I've attempted to use __FILE__ and $0, but neither is returning the
    full path name of script. I get the file name, but not the path in
    which it resides. Anyone have a quick solution?

    def initialize
    @script = $0 # Save where the script is from
    puts "[#{@script}]"
    end

    returns "[AAN_StandardSetup.rb]"


    The script being run is a process setup, where the operations people
    fill in script parameters. The script then creates folder structures
    and performs particular functions. I want to save a copy of the
    script after the operations people have completed filling everything
    in. It would be saved in one of the folders created by the execution
    of the script. That's my dilemma...I want to save it somewhere after
    it has started executing.

    Tips and suggestions are appreciated.
    dvn
     
    dkmd_nielsen, Feb 18, 2008
    #1
    1. Advertising

  2. Is there a particular reason you are having the "operations people"
    modify the script directly rather than having them modify a
    configuration file of some kind that the script reads? If there is a
    fixed set of parameters that need changed, reading them from a file is
    cleaner (YAML would be a good choice, here) than modifying the script,
    and then you can just copy the config file to an archive location when
    you load it.

    Other than that, the only thing I can think of off the top of my head
    is having the script that is being edited not be the main script, but
    instead be required by a wrapper script that uses SCRIPT_LINES__ to
    capture the contents of the required file, and then archives it
    somewhere.

    On Feb 18, 2008 6:49 AM, dkmd_nielsen <> wrote:
    > I would like to write a copy of the current script being executed.
    > I've attempted to use __FILE__ and $0, but neither is returning the
    > full path name of script. I get the file name, but not the path in
    > which it resides. Anyone have a quick solution?
    >
    > def initialize
    > @script = $0 # Save where the script is from
    > puts "[#{@script}]"
    > end
    >
    > returns "[AAN_StandardSetup.rb]"
    >
    >
    > The script being run is a process setup, where the operations people
    > fill in script parameters. The script then creates folder structures
    > and performs particular functions. I want to save a copy of the
    > script after the operations people have completed filling everything
    > in. It would be saved in one of the folders created by the execution
    > of the script. That's my dilemma...I want to save it somewhere after
    > it has started executing.
    >
    > Tips and suggestions are appreciated.
    > dvn
    >
    >
     
    Christopher Dicely, Feb 18, 2008
    #2
    1. Advertising

  3. dkmd_nielsen

    dkmd_nielsen Guest

    On Feb 18, 10:58 am, Christopher Dicely <> wrote:
    > Is there a particular reason you are having the "operations people"
    > modify the script directly rather than having them modify a
    > configuration file of some kind that the script reads? If there is a
    > fixed set of parameters that need changed, reading them from a file is
    > cleaner (YAML would be a good choice, here) than modifying the script,
    > and then you can just copy the config file to an archive location when
    > you load it.
    >
    > Other than that, the only thing I can think of off the top of my head
    > is having the script that is being edited not be the main script, but
    > instead be required by a wrapper script that uses SCRIPT_LINES__ to
    > capture the contents of the required file, and then archives it
    > somewhere.
    >
    > On Feb 18, 2008 6:49 AM, dkmd_nielsen <> wrote:
    >
    > > I would like to write a copy of the current script being executed.
    > > I've attempted to use __FILE__ and $0, but neither is returning the
    > > full path name of script. I get the file name, but not the path in
    > > which it resides. Anyone have a quick solution?

    >
    > > def initialize
    > > @script = $0 # Save where the script is from
    > > puts "[#{@script}]"
    > > end

    >
    > > returns "[AAN_StandardSetup.rb]"

    >
    > > The script being run is a process setup, where the operations people
    > > fill in script parameters. The script then creates folder structures
    > > and performs particular functions. I want to save a copy of the
    > > script after the operations people have completed filling everything
    > > in. It would be saved in one of the folders created by the execution
    > > of the script. That's my dilemma...I want to save it somewhere after
    > > it has started executing.

    >
    > > Tips and suggestions are appreciated.
    > > dvn


    It's a dog chasing its tail. The script is a configuration file. And
    the scripts job is to simplify the creation of the production folder
    structure, copy an applications configuration file, update its
    contents with user specified values and the folder structure
    information, and then execute the application. Using the script
    method was easier to implement. The operations people load the
    script, change some values, press "F5" to execute the script, and
    they're done. The other scenario would involve them locating the
    configuration file, updating it and saving it, going somewhere else
    for the script, updating it and then running it.

    I know it sounds piddly...but trust me. The operations people aren't
    developers. They're not the sharpest knives in the drawer. The
    company keeps pushing us to dumb things down so they can use less and
    less skilled people to do the work.

    Thanks
     
    dkmd_nielsen, Feb 18, 2008
    #3
  4. dkmd_nielsen wrote:
    > I would like to write a copy of the current script being executed.
    > I've attempted to use __FILE__ and $0, but neither is returning the
    > full path name of script. I get the file name, but not the path in
    > which it resides. Anyone have a quick solution?
    >
    > def initialize
    > @script = $0 # Save where the script is from
    > puts "[#{@script}]"
    > end
    >
    > returns "[AAN_StandardSetup.rb]"


    File.expand_path(__FILE__)
    File.expand_path($0)

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
     
    Joel VanderWerf, Feb 18, 2008
    #4
  5. dkmd_nielsen

    dkmd_nielsen Guest

    On Feb 18, 1:07 pm, Joel VanderWerf <> wrote:
    > dkmd_nielsen wrote:
    > > I would like to write a copy of the current script being executed.
    > > I've attempted to use __FILE__ and $0, but neither is returning the
    > > full path name of script. I get the file name, but not the path in
    > > which it resides. Anyone have a quick solution?

    >
    > > def initialize
    > > @script = $0 # Save where the script is from
    > > puts "[#{@script}]"
    > > end

    >
    > > returns "[AAN_StandardSetup.rb]"

    >
    > File.expand_path(__FILE__)
    > File.expand_path($0)
    >
    > --
    > vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


    I tried that. I got the dataset name and that's it. Is it an O/S
    thing?

    Thanks, dvn
     
    dkmd_nielsen, Feb 18, 2008
    #5
  6. dkmd_nielsen wrote:
    > On Feb 18, 1:07 pm, Joel VanderWerf <> wrote:
    >> dkmd_nielsen wrote:
    >>> I would like to write a copy of the current script being executed.
    >>> I've attempted to use __FILE__ and $0, but neither is returning the
    >>> full path name of script. I get the file name, but not the path in
    >>> which it resides. Anyone have a quick solution?
    >>> def initialize
    >>> @script = $0 # Save where the script is from
    >>> puts "[#{@script}]"
    >>> end
    >>> returns "[AAN_StandardSetup.rb]"

    >> File.expand_path(__FILE__)
    >> File.expand_path($0)
    >>
    >> --
    >> vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

    >
    > I tried that. I got the dataset name and that's it. Is it an O/S
    > thing?


    What do you mean by dataset?

    What OS are you using?

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
     
    Joel VanderWerf, Feb 18, 2008
    #6
  7. dkmd_nielsen

    7stud -- Guest

    dkmd_nielsen wrote:
    > On Feb 18, 1:07 pm, Joel VanderWerf <> wrote:
    >>
    >> > returns "[AAN_StandardSetup.rb]"

    >>
    >> File.expand_path(__FILE__)
    >> File.expand_path($0)
    >>
    >> --
    >> vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

    >
    > I tried that. I got the dataset name and that's it. Is it an O/S
    > thing?
    >


    Let's find out. mac osx 10.4.7:

    puts File.expand_path(__FILE__)
    puts File.expand_path($0)

    --output:--
    /Users/me/2testing/dir1/r1test.rb
    /Users/me/2testing/dir1/r1test.rb
    --
    Posted via http://www.ruby-forum.com/.
     
    7stud --, Feb 18, 2008
    #7
  8. Looking through _The Ruby Way_ for something else, I ran into
    something that could be used here. If you end the source of your
    script with an __END__ marker, you can call DATA.rewind (DATA is a
    global constant IO object for the source file that starts out at a
    position just after the __END__) and then access the source code of
    through DATA.

    On Feb 18, 2008 9:20 AM, dkmd_nielsen <> wrote:
    > On Feb 18, 10:58 am, Christopher Dicely <> wrote:
    > > Is there a particular reason you are having the "operations people"
    > > modify the script directly rather than having them modify a
    > > configuration file of some kind that the script reads? If there is a
    > > fixed set of parameters that need changed, reading them from a file is
    > > cleaner (YAML would be a good choice, here) than modifying the script,
    > > and then you can just copy the config file to an archive location when
    > > you load it.
    > >
    > > Other than that, the only thing I can think of off the top of my head
    > > is having the script that is being edited not be the main script, but
    > > instead be required by a wrapper script that uses SCRIPT_LINES__ to
    > > capture the contents of the required file, and then archives it
    > > somewhere.
    > >
    > > On Feb 18, 2008 6:49 AM, dkmd_nielsen <> wrote:
    > >
    > > > I would like to write a copy of the current script being executed.
    > > > I've attempted to use __FILE__ and $0, but neither is returning the
    > > > full path name of script. I get the file name, but not the path in
    > > > which it resides. Anyone have a quick solution?

    > >
    > > > def initialize
    > > > @script = $0 # Save where the script is from
    > > > puts "[#{@script}]"
    > > > end

    > >
    > > > returns "[AAN_StandardSetup.rb]"

    > >
    > > > The script being run is a process setup, where the operations people
    > > > fill in script parameters. The script then creates folder structures
    > > > and performs particular functions. I want to save a copy of the
    > > > script after the operations people have completed filling everything
    > > > in. It would be saved in one of the folders created by the execution
    > > > of the script. That's my dilemma...I want to save it somewhere after
    > > > it has started executing.

    > >
    > > > Tips and suggestions are appreciated.
    > > > dvn

    >
    > It's a dog chasing its tail. The script is a configuration file. And
    > the scripts job is to simplify the creation of the production folder
    > structure, copy an applications configuration file, update its
    > contents with user specified values and the folder structure
    > information, and then execute the application. Using the script
    > method was easier to implement. The operations people load the
    > script, change some values, press "F5" to execute the script, and
    > they're done. The other scenario would involve them locating the
    > configuration file, updating it and saving it, going somewhere else
    > for the script, updating it and then running it.
    >
    > I know it sounds piddly...but trust me. The operations people aren't
    > developers. They're not the sharpest knives in the drawer. The
    > company keeps pushing us to dumb things down so they can use less and
    > less skilled people to do the work.
    >
    > Thanks
    >
    >
     
    Christopher Dicely, Feb 20, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    2
    Views:
    1,233
  2. Replies:
    26
    Views:
    2,119
    Roland Pibinger
    Sep 1, 2006
  3. Prashant
    Replies:
    2
    Views:
    345
    Nick Stinemates
    Apr 18, 2008
  4. ARGENTINA
    Replies:
    4
    Views:
    171
    Joe Smith
    Dec 30, 2004
  5. Replies:
    4
    Views:
    189
    Josef Moellers
    Oct 27, 2007
Loading...

Share This Page