?
Solved

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

Posted on 2003-03-25
10
Medium Priority
?
5,689 Views
Last Modified: 2012-05-07
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
0
Comment
Question by:j_f_kelley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 7

Expert Comment

by:billious
ID: 8203783
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
0
 

Author Comment

by:j_f_kelley
ID: 8204442
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
0
 
LVL 7

Expert Comment

by:billious
ID: 8207294
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
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:j_f_kelley
ID: 8219703
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
0
 

Author Comment

by:j_f_kelley
ID: 8220969
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
0
 

Author Comment

by:j_f_kelley
ID: 8221358
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
0
 
LVL 7

Accepted Solution

by:
billious earned 150 total points
ID: 8222032
if
"ECHO To: jeff@foo.com | sendmail"

 where sendmail is sendmail.bat works happily, then if you can persuade Perl to generate a simple file (perlout.txt), shouldn't

type perlout.txt | sendmail

work?

...Bill
0
 
LVL 1

Expert Comment

by:curtwade
ID: 8227706
Would having a 1-byte text file with ASCII 026 (i.e., <Alt-NumPad 026>) in it work?
0
 
LVL 4

Expert Comment

by:patrvic
ID: 8251628
precsily what's required here is Ctrl+Z action in a batch file. i used " ^Z " but this does not work...
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question