Calling Exec() in Windows versus UNIX

Discussion in 'Ruby' started by Matthew Williams, Sep 24, 2007.

  1. I have the following line in a small app:

    exec("charting/RequestByProject.jar",params[:name]')

    When run in a UNIX environment it works fine.

    However, moving it over to Windows and trying to run:
    exec("charting\RequestByProject.jar",params[:name]')

    Returns nothing... But if I jump to the Windows command line and run:
    RequestByProject.jar project

    It runs fine.

    Any thoughts why it's not executing from my Ruby code in Windows?
    --
    Posted via http://www.ruby-forum.com/.
    Matthew Williams, Sep 24, 2007
    #1
    1. Advertising

  2. Matthew Williams

    Marc Heiler Guest

    Matthew Williams wrote:
    > I have the following line in a small app:
    >
    > exec("charting/RequestByProject.jar",params[:name]')
    >
    > When run in a UNIX environment it works fine.
    >
    > However, moving it over to Windows and trying to run:
    > exec("charting\RequestByProject.jar",params[:name]')
    >
    > Returns nothing... But if I jump to the Windows command line and run:
    > RequestByProject.jar project
    >
    > It runs fine.
    >
    > Any thoughts why it's not executing from my Ruby code in Windows?



    Did you try with system() or `` instead? Or maybe IO.
    And tried File.exist? on it too, to see if the path was working?

    Last but not least, maybe it wasn't in the path. But if it can be found,
    it should even work on Windows using something like
    result = `RequestByProject.jar #{params[:name]}`
    and peeking at the result, and the error code

    Just some thoughts :)
    --
    Posted via http://www.ruby-forum.com/.
    Marc Heiler, Sep 24, 2007
    #2
    1. Advertising

  3. Doan, Alex wrote:
    >> However, moving it over to Windows and trying to run:
    >> exec("charting\RequestByProject.jar",params[:name]')

    >
    > You're escaping the 'R' in the above command.
    >
    > You can leave it exec("charting/RequestByProject.jar",params[:name]')
    > and it would still work on window.


    I initially left it like that but when it wasn't working thought I had
    to flip the / but it still didn't work. Then put the jar in the root of
    my app and tried running it but still nothing. But I can still go to
    the command line and run it with no problems.

    If I only didn't need to run this in Windows... :)

    I'm also trying "java -jar charting/RequestByProject.jar" but exec()
    doesn't seem to like the spaces, any idea how I could execute it that
    way?

    Thanks
    --
    Posted via http://www.ruby-forum.com/.
    Matthew Williams, Sep 24, 2007
    #3
  4. Marc Heiler wrote:
    > Matthew Williams wrote:
    >> I have the following line in a small app:
    >>
    >> exec("charting/RequestByProject.jar",params[:name]')
    >>
    >> When run in a UNIX environment it works fine.
    >>
    >> However, moving it over to Windows and trying to run:
    >> exec("charting\RequestByProject.jar",params[:name]')
    >>
    >> Returns nothing... But if I jump to the Windows command line and run:
    >> RequestByProject.jar project
    >>
    >> It runs fine.
    >>
    >> Any thoughts why it's not executing from my Ruby code in Windows?

    >
    >
    > Did you try with system() or `` instead? Or maybe IO.
    > And tried File.exist? on it too, to see if the path was working?
    >
    > Last but not least, maybe it wasn't in the path. But if it can be found,
    > it should even work on Windows using something like
    > result = `RequestByProject.jar #{params[:name]}`
    > and peeking at the result, and the error code
    >
    > Just some thoughts :)


    @result = system("RequestByProject.jar "+params[:name]+"")

    That did the trick.

    I forgot about all the other system call methods... Thanks!
    --
    Posted via http://www.ruby-forum.com/.
    Matthew Williams, Sep 24, 2007
    #4
  5. Matthew Williams wrote:
    > exec("charting/RequestByProject.jar",params[:name]')


    This works for me:

    irb(main):004:0> exec "C:/Program Files/JGSoft/EditPadLite/EditPad.exe"

    HTH.

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
    Joel VanderWerf, Sep 24, 2007
    #5
  6. Joel VanderWerf wrote:
    > Matthew Williams wrote:
    >> exec("charting/RequestByProject.jar",params[:name]')

    >
    > This works for me:
    >
    > irb(main):004:0> exec "C:/Program Files/JGSoft/EditPadLite/EditPad.exe"


    This works too:

    exec "C:/Program Files/JGSoft/EditPadLite/EditPad.exe", "C:/tmp/foo.txt"

    Note the difference between #exec and #system: system blocks and returns
    when the child is done, but exec causes the current process to be
    replaced with the child.

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
    Joel VanderWerf, Sep 24, 2007
    #6
    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. Hal Vaughan
    Replies:
    11
    Views:
    1,107
    Gordon Beaton
    May 22, 2006
  2. tedsuzman
    Replies:
    2
    Views:
    7,080
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  3. Ted
    Replies:
    1
    Views:
    462
    Duncan Booth
    Jul 22, 2004
  4. Robert Evans
    Replies:
    10
    Views:
    212
    Pit Capitain
    Oct 26, 2005
  5. Paul Butcher
    Replies:
    12
    Views:
    708
    Gary Wright
    Nov 28, 2007
Loading...

Share This Page