Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-25
10
Medium Priority
?
5,968 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
9 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
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

580 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