Calling Exec() in Windows versus UNIX

M

Matthew Williams

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?
 
M

Marc Heiler

Matthew said:
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 :)
 
M

Matthew Williams

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
 
M

Matthew Williams

Marc said:
Matthew said:
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!
 
J

Joel VanderWerf

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

This works for me:

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

HTH.
 
J

Joel VanderWerf

Joel said:
Matthew said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top