[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 576
  • Last Modified:

How can I run a .bat file from ksh?

I must be able to pass the .bat file a single fully qualified file name from the POSIX subsystem under NT4 sp6a

I have tried /bin/runwin32 but it appears to expect either an .exe or something to have a real window so runwin32 .../cmd.exe /C .../mybat.bat parm1 simply opens a cmd.exe session.  I tried runwin32 .../mybat.bat parm1 and it appeared to simply scroll the .bat file by as if it was trying to execute a unix script which it was not happy with.

I have also tried the method discussed at
http://sources.redhat.com/ml/cygwin/2000-09/msg00620.html
but that gave me no joy.

$ksh -x .../mybat.bat parm1 did the same thing as the second attempt at runwin32 above.
$sh -x .../mybat.bat parm1 was happier but still did nothing leaving only the complaints about the odd REM of if statements.



0
JohnstonB
Asked:
JohnstonB
2 Solutions
 
wesly_chenCommented:
Hi,

  What's in mybat.bat? A collection of commands such as
-----
command1 parm1
command2 parm2
...
------
You can write a script script call mybat.sh
-----
#!/bin/sh
runwin32  command1 parm1
runwin32 command2 parm2
...
----

Wesly
0
 
bearwareCommented:
Im using the cygwin posix environment under NT5 (XP)

I just type:
./command.bat param1 param2 etc...

note: / charecters in the parameters should be the wrong way around (replaced by \) and then escaped so as not to be replaced by the posix shell so \\ or "\" or '\' type of thing.
0
 
ahoffmannCommented:
by ".bat file" do you mean a text file containing DOS commands?
If so, you need a DOS (or windows) emulation software to do this.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
JohnstonBAuthor Commented:
I'd like to award partial points (200) to Wesly for confirming that I was heading the right direction.  Then, umpires permitting, I'll increase the value to 400 and award 200 points for an answer to the question at the end of this reply.

Bear with me please 'cause I'm programming like a paramecium... flailing along in a petri dish until I run into an obstacle and then bouncing my way around it.  Of course, in my tiny vnc window backtick looked a whole lot like apostrophe... sigh.  FYI : the context of this is to convert a .pdf sent to a parent from lbmsys' unique print queue manager and use acrord32.exe version4 to convert the file in to a printer-ready file using APPXuPDF.bat

I did muck around and arrive at a solution that uses Wesly's post as a starting point although this mucking

took quite a number of hours of me deducing ksh behaviour in trial-and-error mode.  My new setfax.xerox script looks like
...
#!/bin/ksh
cd //C/UniQueNT
ntname=`posixpath2nt $1`
dname=`dirname $1`
bname=`basename $1 .pdf`
#      We are assuming that only two types of files will be sent:
#      Without an extension or .pdf
if [ -f $dname/$bname.pdf ]
then
   runwin32 cmd.exe /C "D:\APPX\Data\APPXuPDF.bat" "$ntname"
fi
cffname=$dname/$bname.CFF
//C/OpenNT/usr/spool/formfont/bin/formfont $2 $3 $4 $5 | ./addfax.xerox $cffname
...
So, you see Wesly was pointing me in the right direction though I had to just "Keep Banging The Rocks

Together".

The parent of the above script is an output filtre on unique reading
...
//C/UniQueNT/setfax.xerox $fullpath -u -f$form -$options -t$title
...
where $fullpath, u, $form, $options and $title are macro substitutions for the stuff sent from unique.  (Normally formfont is invoked with just four parameters in addition to stinput per the structure in setfax.xerox prior to the pipe.

In setfax.xerox addfax.xerox expects a file ending in .CFF and CURRENTLY looks like
...
//C/OpenNT/bin/cat $1
//C/OpenNT/bin/cat -
//C/OpenNT/bin/rm -f $1
...
and it pre-pends a file to its stinput, right? (The .CFF file contains the @PJL commands for using a xerox DC 400 as a fax mchine.)

In APPXuPDF.bat $dname/$bname.pdf is converted to $dname/$bname.raw retaining the input .pdf

For the additional 200 points I need to effectively "swap" the stinput of the parent from the .pdf file to the

.raw file.  Would the following version of addfax.xerox work if it were passed a .CFF file?
...
dname=`dirname $1`
bname=`basename $1 .pdf`
#      We are assuming that only two types of files will be sent:
#      Without an extension or .pdf which was converted to a .raw file in parent
//C/OpenNT/bin/cat $1
if [ -f $dname/$bname.pdf ]
then
      //C/OpenNT/bin/cat $dname/$dname.raw
else
      //C/OpenNT/bin/cat -
fi
//C/OpenNT/bin/rm -f $1
0
 
JohnstonBAuthor Commented:
Opps... i can only split 200 to Wesly if I also award the other 200.  They're still up for grabs pending the answer to the question at the bottom of my comment.
0
 
JohnstonBAuthor Commented:
FYI.. part of the reason that I didn't award all point to Wesly is that the thin being invoked by runwin32 is a .bat file containing...
...
REM      To decode things read up on the substitution parsing functions after tilde but before parmnum
REM      This assumes that $1.mfg was created by appx_print to contain the printer name which will help
REM      decide which driver to use to create the .pdf
REM         THIS ONLY WORKS WITH VERSION 4 OF ACRORD32
REM         (version 5 hangs in background mode and version 6 won't even try)
setlocal

REM      Delete a previous .raw file if it's there
del /f %~dpn1.raw

IF NOT EXIST %~dpn1%.mfg GOTO ENDBATCH
REM      Which printer type, XEROX or something else?
REM      (Send .cfg lines with "XEROX" to a .mfg and if 0-byte then false.)
findstr /i /c:"XEROX" %~dpn1.mfg > %~dpn1.mf0
for /F "Tokens=3" %%S in ('DIR %~dpn1.mf0 /-C ^| FIND /i "%~n1.mf0"') Do SET FSIZE=%%S
del %~dpn1.mf0

IF %FSIZE%==0 GOTO NOXEROX
REM      Create raw file from .pdf using XEROX Printer Driver
"C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe" /o /h /t %1 XEROX c:\winnt\system32\spool\drivers\w32x86\x44xlk.dll %~dpn1%.raw
GOTO ENDBATCH

:NOXEROX
REM      Create raw file from .pdf using HP LaserJet 4+ Printer Driver
"C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe" /o /h /t %1 RECEPT c:\winnt\system32\spool\drivers\w32x86\hpbfcf2.dll %~dpn1%.raw

:ENDBATCH

endlocal
...
0
 
wesly_chenCommented:
> dname=`dirname $1`
> bname=`basename $1 .pdf`  <=== should be  "bname=`basename $1"
> #     We are assuming that only two types of files will be sent:
> #     Without an extension or .pdf which was converted to a .raw file in parent
> //C/OpenNT/bin/cat $1
> if [ -f $dname/$bname.pdf ]
> then
>      //C/OpenNT/bin/cat $dname/$dname.raw
> else
>      //C/OpenNT/bin/cat -
> fi
>  //C/OpenNT/bin/rm -f $1

Wesly
0
 
JohnstonBAuthor Commented:
Thanks Wesly.  You pointed out a typo.  It should really be
bname='basename $1 .CFF'
since setfax.xerox is sending $cffname which has this extension which I want to first remove before looking to see if I'm dealing with a .pdf (which gave rise to a .raw in setfax.xerox by calling APPXuPDF.bat).

I'll award you all 400.

Just to make sure I understand all of this...
   "cat $1" places the $1 in stdoutput
then
   "cat $dname/$bname.raw" appends my .raw file to stdoutput
   (Oops!  Just caught that $dname.raw vs. $bname.raw typo myself.)
XOR
   "cat -" appends stdinput to stdoutput

Sorry for being such a newbie but I got bit by something seemingly totally benign a couple of says ago.
0
 
wesly_chenCommented:
  "cat $1" places the $1 in stdoutput   <=== Yes
   "cat $dname/$bname.raw" appends my .raw file to stdoutput  <== Yes
   "cat -" appends stdinput to stdoutput  <=== Yes

Wesly
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now