Link to home
Start Free TrialLog in
Avatar of j_f_kelley
j_f_kelley

asked on

Simulate ctrl+z in Batch file? Copy CON:+ctrlz>myfile

I'm writing a simulated sendmail batch file for localhost debugging.  I'd like my batch file to take the console that was piped to the batch file and redirect that console to a file.

I could use this: ECHO CON: > console.log, but, I'm not there to hit the Ctrl+Z character.  

I bet I'm just missing one simple trick, how in vanilla dos (e.g, Win2K) do I echo an arbitrary character (including ctrl+z)?  Ctrl-Z is apparently a decimal 032, hex 1A.  I'm thinking something like this:

ECHO CON: + \032 > console.log
Avatar of billious
billious

Are you trying to simulate a console input by piping data to a program, and you need a control-Z to terminate that data?

If so, try

datagenerationprogram >x.txt
copy/y x.txt y.txt
datareceivingprogram <y.txt

Otherwise, AFAIAA con: will look for console input, so you ARE there to type the ^Z - aren't you??

...Bill
Avatar of j_f_kelley

ASKER

Thank you for the quick response!

I won't be there at the keyboard.  The http server will invoke my batch file and pipe some text to it.  I'd like my batch file to intercept that piped console input and stuff it in a file, unattended.

Background: for local debugging, I have a \usr\lib\sendmail.bat file that is invoked by my CGI perl FormMail.pl (thinking it's the REAL sendmail).  Perl does an open() on "/usr/lib/sendmail" (which resolves to my batch file) and writes lines of email text to it (hence the console).

I was hoping that there would be an ECHO or COPY command that I could use to redirect what's on the console to a file (without anyone there to hit Ctrl+Z).  Like:

COPY CON: + somespecialescapezthing  myfile.log
or:
ECHO CON: + somespecialescapezthing > myfile.log

I would test my file with a command like:

ECHO Test email string | sendmail.bat
I'm not sure that your Perl script actually looks to MSDOS as though its the CON: device.

ECHO something |batchname won't work, AFAIAA.

batchname "something"

will work - quotes around the argument if it contains certain characters like spaces, and you may have to prefix certain others (like <>|&) with a caret (^)

You then input to sendmail by

sendmail ... %1 ....

(%1 simply substitutes the first argument to the batch)

OR, if sendmail really needs a ^Z,

ECHO something >filename
copy/a filename anotherfilename
batchname

then, within batchname,

sendmail ... <anotherfilename ...

which will simulate entering something into sendmail via the console

If sendmail doesn't need the ^Z, then

ECHO something >filename
batchname

then, within batchname,

sendmail ... <filename ...

OR
ECHO something >filename
batchname filename

then, within batchname,

sendmail ... <%1 ...

...Bill
Thank you for your patience.  I'm afraid I'm unclear about what I want to do and am asking the wrong question.  It's a combination Perl and Dos thing, I think.

In essence, the FormMail.pl perl program does this:

$mailprog = '/usr/lib/sendmail';
open(MAIL,"|$mailprog -t");
print MAIL "To: john@doe.com\n";
print MAIL "From: me@my.com\n";
print MAIL "(rest of message)\n";
close MAIL;

When running in local server (Tiny.exe) debug mode, I have tricked it by creating a file c:\usr\lib\sendmail.bat, which gets called and sees all the environment variables that the CGI system offers and also recognizes that "-t" as %1.

The problem is, I don't know what becomes of the text that the perl program "printed" to my batch file.  I was assuming they were waiting on the CON: "console" queue.  

Since I couldn't figure out how to copy the pending console queue to a log file (without being there to manually press Ctl+Z), I wrote a Rexx script (where I DO know how to look at the pending console queue, using the Lines() function) and now I call that script from sendmail.bat.

Here's where it gets wierd.  If I invoke my sendmail.bat manually with "ECHO To: jeff@foo.com | sendmail", then everything is hunky dory and my rexx script sees the console lines and can do all the logging/debugging stuff.  

However, if I let my perl script open the sendmail.bat and do its "print" commands against it and close it, that information is NOT on the console queue; it disappears into hyperspace or something.  Presumably, if I had the "real" sendmail installed, it would know how to pull that stuff in since it does just fine on the web server version.

As I read this, I begin to wonder if the real problem here isn't my own comprehensive ignorance about what are probably the most basic concepts.  Sigh.

Unless I'm missing something really simple here, I fear my question ceases to be a 50-point quicky and enters the realm of a 2,000,000 point re-education effort!  But, thanks for your attention!

JF
Thank you for your patience.  I'm afraid I'm unclear about what I want to do and am asking the wrong question.  It's a combination Perl and Dos thing, I think.

In essence, the FormMail.pl perl program does this:

$mailprog = '/usr/lib/sendmail';
open(MAIL,"|$mailprog -t");
print MAIL "To: john@doe.com\n";
print MAIL "From: me@my.com\n";
print MAIL "(rest of message)\n";
close MAIL;

When running in local server (Tiny.exe) debug mode, I have tricked it by creating a file c:\usr\lib\sendmail.bat, which gets called and sees all the environment variables that the CGI system offers and also recognizes that "-t" as %1.

The problem is, I don't know what becomes of the text that the perl program "printed" to my batch file.  I was assuming they were waiting on the CON: "console" queue.  

Since I couldn't figure out how to copy the pending console queue to a log file (without being there to manually press Ctl+Z), I wrote a Rexx script (where I DO know how to look at the pending console queue, using the Lines() function) and now I call that script from sendmail.bat.

Here's where it gets wierd.  If I invoke my sendmail.bat manually with "ECHO To: jeff@foo.com | sendmail", then everything is hunky dory and my rexx script sees the console lines and can do all the logging/debugging stuff.  

However, if I let my perl script open the sendmail.bat and do its "print" commands against it and close it, that information is NOT on the console queue; it disappears into hyperspace or something.  Presumably, if I had the "real" sendmail installed, it would know how to pull that stuff in since it does just fine on the web server version.

As I read this, I begin to wonder if the real problem here isn't my own comprehensive ignorance about what are probably the most basic concepts.  Sigh.

Unless I'm missing something really simple here, I fear my question ceases to be a 50-point quicky and enters the realm of a 2,000,000 point re-education effort!  But, thanks for your attention!

JF
Thank you for your patience.  I'm afraid I'm unclear about what I want to do and am asking the wrong question.  It's a combination Perl and Dos thing, I think.

In essence, the FormMail.pl perl program does this:

$mailprog = '/usr/lib/sendmail';
open(MAIL,"|$mailprog -t");
print MAIL "To: john@doe.com\n";
print MAIL "From: me@my.com\n";
print MAIL "(rest of message)\n";
close MAIL;

When running in local server (Tiny.exe) debug mode, I have tricked it by creating a file c:\usr\lib\sendmail.bat, which gets called and sees all the environment variables that the CGI system offers and also recognizes that "-t" as %1.

The problem is, I don't know what becomes of the text that the perl program "printed" to my batch file.  I was assuming they were waiting on the CON: "console" queue.  

Since I couldn't figure out how to copy the pending console queue to a log file (without being there to manually press Ctl+Z), I wrote a Rexx script (where I DO know how to look at the pending console queue, using the Lines() function) and now I call that script from sendmail.bat.

Here's where it gets wierd.  If I invoke my sendmail.bat manually with "ECHO To: jeff@foo.com | sendmail", then everything is hunky dory and my rexx script sees the console lines and can do all the logging/debugging stuff.  

However, if I let my perl script open the sendmail.bat and do its "print" commands against it and close it, that information is NOT on the console queue; it disappears into hyperspace or something.  Presumably, if I had the "real" sendmail installed, it would know how to pull that stuff in since it does just fine on the web server version.

As I read this, I begin to wonder if the real problem here isn't my own comprehensive ignorance about what are probably the most basic concepts.  Sigh.

Unless I'm missing something really simple here, I fear my question ceases to be a 50-point quicky and enters the realm of a 2,000,000 point re-education effort!  But, thanks for your attention!

JF
ASKER CERTIFIED SOLUTION
Avatar of billious
billious

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Would having a 1-byte text file with ASCII 026 (i.e., <Alt-NumPad 026>) in it work?
precsily what's required here is Ctrl+Z action in a batch file. i used " ^Z " but this does not work...