Calling Exec() in Windows versus UNIX

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?

Matthew W. 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 :slight_smile:

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.

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… :slight_smile:

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

Matthew W. wrote:

exec(“charting/RequestByProject.jar”,params[:name]’)

This works for me:

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

HTH.

Joel VanderWerf wrote:

Matthew W. 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.

Marc H. wrote:

Matthew W. 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 :slight_smile:

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

That did the trick.

I forgot about all the other system call methods… Thanks!