Windows - calling system with multiple parms

J

John Reed

I'm having a problem getting a system call to Windows XP to work. I
upgraded my Ruby from 1.6.8 to 1.8.1 recently.

System info:
ruby –v
ruby 1.8.1 (2003-12-25) [I-386-mswin32]


FWIW, my .bat file is passing the directory path for ghostscipt exe
and the path for the ghostscript font directory, as well as the
printer code for the ghostscript emulation.

This line of code worked when I was on 1.6.8:

system("dcpropgst.bat", [@@gsdir, @@gsfontdir, @@prttxt])

Now, I get the TypeError: cannot convert Array into String

I've tried many different ways of calling system with one of them
being:

system( %{"dcpropgst.bat", #@@gsdir, #@@gsfontdir, #@@prttxt} )

In all cases where I can see that it is calling the .bat file, only
the 1st parameter is being passed.


I've spent many hours trying to get it to work. What do I need to
change so all 3 parms are passed?

Thanks,

John Reed
 
F

Florian Gross

John said:
I'm having a problem getting a system call to Windows XP to work. I
upgraded my Ruby from 1.6.8 to 1.8.1 recently.

system("dcpropgst.bat", [@@gsdir, @@gsfontdir, @@prttxt])

irb(main):011:0> system("ruby", "-v", "-c", "-e()")
ruby 1.8.2 (2004-07-16) [i386-mswin32]
Syntax OK

Does this not work for you?
 
A

Austin Ziegler

I'm having a problem getting a system call to Windows XP to work. I
upgraded my Ruby from 1.6.8 to 1.8.1 recently.

System info:
ruby –v
ruby 1.8.1 (2003-12-25) [I-386-mswin32]

FWIW, my .bat file is passing the directory path for ghostscipt exe
and the path for the ghostscript font directory, as well as the
printer code for the ghostscript emulation.

This line of code worked when I was on 1.6.8:

system("dcpropgst.bat", [@@gsdir, @@gsfontdir, @@prttxt])

Try changing this to:
system("dcpropgst.bat", @@gsdir, @@gsfontdir, @@prttxt)

If you can't predict how many parameters, do this:
params = [ @@gsdir, @@gsfontdir, @@prttxt ]
system("dcpropgst.bat, *params)

-austin
 
J

John Reed

Florian Gross asked:
irb(main):011:0> system("ruby", "-v", "-c", "-e()")
ruby 1.8.2 (2004-07-16) [i386-mswin32]
Syntax OK

Does this not work for you?


Florian, it does work for me:

C:\ruby>irb
irb(main):001:0> system("ruby", "-v", "-c", "-e()")
ruby 1.8.1 (2003-12-25) [i386-mswin32]
Syntax OK
=> true

John
 
J

John Reed

Austin,
AZ> Try changing this to:
AZ> system("dcpropgst.bat", @@gsdir, @@gsfontdir, @@prttxt)

This doesn't call the .bat file at all.AZ> If you can't predict how many parameters, do this:
AZ> params = [ @@gsdir, @@gsfontdir, @@prttxt ]
AZ> system("dcpropgst.bat", *params)

Neither does this one.

If I wanted to hard code the paths as well as the printer code, it
will work.

What I see happening is that when I pass the 3 parameters as I think
that they should be passed is that the 2nd & 3rd params aren't in fact
passed.

Here is dcpropgst.bat:
%1 -I%2 -sDEVICE=%3 -dNOPAUSE print.ps -c quit

This:
system( %{"dcpropgst.bat",#{@@gsdir} #{@@gsfontdir} #{@@prttxt}} )

(or this because the braces aren't needed)
system( %{"dcpropgst.bat",#@@gsdir #@@gsfontdir #@@prttxt} )

Causes this:
C:\JDR\Ruby>C:\DCPro\gs\gs8.14\bin\gswin32.exe -I -sDEVICE= -dNOPAUSE
print.ps -c quit

Putting commas between the params is also irrelevant, in my testing,
as they all produce the above result.


John Reed
 
F

Florian Gross

John said:
What I see happening is that when I pass the 3 parameters as I think
that they should be passed is that the 2nd & 3rd params aren't in fact
passed.

Here is dcpropgst.bat:
%1 -I%2 -sDEVICE=%3 -dNOPAUSE print.ps -c quit

This:
system( %{"dcpropgst.bat",#{@@gsdir} #{@@gsfontdir} #{@@prttxt}} )

(or this because the braces aren't needed)
system( %{"dcpropgst.bat",#@@gsdir #@@gsfontdir #@@prttxt} )

p [@@gsdir, @@gsfontdir, @@prttxt]

I expect all of those to be nil or empty strings. I can't tell you how
to fix that without having the source code of your application.
 
J

John Reed

p [@@gsdir, @@gsfontdir, @@prttxt]
I expect all of those to be nil or empty strings. I can't tell you how
to fix that without having the source code of your application.

Ah, if only it were that easy. I do a "puts" of those variables before
the system call and they are properly populated.

I still don't get why it worked with 1.6.8 and not 1.8.1...doesn't
make sense to me.

John Reed
 
J

John Reed

Lyndon Samson said:
Cant you do

system("dcpropgst.bat #{@@gsdir} #{@@gsfontdir} #{@@prttxt}")

?

Same results as before, not passing the 2nd and 3rd parameters.

I put an echo in the .bat file to see the parameters, so here is the
results of the .bat file as it is called:

C:\JDR\Ruby>echo C:\DCPro\gs\gs8.14\bin\gswin32.exe
C:\DCPro\gs\gs8.14\bin\gswin32.exe

C:\JDR\Ruby>echo
ECHO is on.

C:\JDR\Ruby>echo
ECHO is on.

C:\JDR\Ruby>C:\DCPro\gs\gs8.14\bin\gswin32.exe -I -sDEVICE= -dNOPAUSE
print.ps -c quit

Here is the complete .bat file:
echo %1
echo %2
echo %3
%1 -I%2 -sDEVICE=%3 -dNOPAUSE print.ps -c quit


I do have 3 "puts" right before the system call so I can see that all
of the params have the values that I expect them to.

@@gsdir = C:\DCPro\gs\gs8.14\bin\gswin32.exe
@@gsfontdir = C:\DCPro\gs\gs8.14\bin\fonts
@@prttxt = cdj550

Well, I'm back to the drawing board on this problem....

JReed
 
L

Lyndon Samson

Try using literals rather than your class variables.

Then use instance variables.
 
J

John Reed

Lyndon Samson said:
Try using literals rather than your class variables.

Then use instance variables.

Good ideas, but I never could make it work with more than 1 parameter.
I found a workaround in the batch file itself.

John Reed
 
N

Nicholas Van Weerdenburg

Maybe try forward slashes in the paths in the parameters. Possibly
something funky is happening there.

Also, it might a good idea to construct the simplest test case and post
it for other XPers to try.

Regards,
Nick
 
J

John Reed

Nicholas Van Weerdenburg said:
Maybe try forward slashes in the paths in the parameters. Possibly
something funky is happening there.

Also, it might a good idea to construct the simplest test case and post
it for other XPers to try.

Regards,
Nick
Nick, I changed my Ruby program to pass only 1 parm to my batch file,
and here's my batch file:
SET curdir=%CD%
SET gsdir=%curdir%\gs\gs8.14\bin\gswin32.exe
SET gsfontdir=%curdir%\gs\gs8.14\bin\fonts
%gsdir% -I%gsfontdir% -sDEVICE=%1 -dNOPAUSE print.ps -c quit

John
 

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

Staff online

Members online

Forum statistics

Threads
474,162
Messages
2,570,893
Members
47,432
Latest member
GTRNorbert

Latest Threads

Top