1

I am trying to redirect a PS output to a file and process it further. For this I am using the Printer Port Redirection RedMon which is sending the output to CMD.exe

C:\Windows\system32\cmd.exe

As arguments I expected that something like the following should work, but it does not. "%1" contains the user input for filename.

/c >"%1"

or

/c 1>"%1"

or

/c |"%1"

or

/c > "%1" 2>&1

What almost works if I send the output to a batch file which writes it then to file.

/c WriteOutput.bat "%1"

However, the batch file is somehow altering the file (skipping empty lines, and ignoring exclamation marks and so on...) If possible I want to avoid a batch file. Is there a way to get it "directly" to a file? Select "Print to FILE" in the printer options is not an option for me. I want the same end result but via cmd.exe being able to process it further. Any ideas?

Edit: Well, that's the batch file I used. It neglects empty lines and space at the beginning.

@echo off
setlocal
set FileName=%1
echo(>%FileName%.ps
for /F "tokens=*" %%A in ('more') do (
    echo %%A>>%FileName%.ps
)
theozh
  • 22,244
  • 5
  • 28
  • 72
  • _"However, the batch file is somehow altering the file (skipping empty lines, and ignoring exclamation marks and so on...)"_ -- unless you do not show the said batch file, how should we be able to fix it? I guess you are using a `for /F` loop (skipping empty lines) and delayed expansion (losing exclamation marks)... – aschipfl Dec 20 '16 at 16:16
  • Thanks @aschipfl, well, actually, I was not asking for fixing the batch script which I got in different variants here from Stackoverflow. Instead I would like to avoid the batch script. Well, only if it doesn't work directly I probably need to go back to a batch script :-(. – theozh Dec 20 '16 at 16:28

1 Answers1

1

Well, so far I still haven't found a direct way to write STDIN via RedMon via CMD.exe to a file. As @aschipfl wrote, all the versions with for /F will skip lines and ignore certain characters.

However, with the following batch script (via RedMon) I end up with a "correct looking" file on disk.

C:\Windows\system32\cmd.exe /c WritePS.bat "%1"

"%1" contains the user input for filename without extension. The Batch-File WritePS.bat looks as simple as this:

@echo off & setlocal
set FileName=%1.ps
more > "%FileName%"

However,

the resulting Postscript file is different from a file which I "Print to FILE" via the Postscript-Printer setup. I am pretty sure that all the printer settings which I can set are the same in both cases. If anybody has an idea why there might be a difference, please let me know.

theozh
  • 22,244
  • 5
  • 28
  • 72