How can I write to the parallel port from the Windows Command line? - command-line

How can I write to parallel port through Windows XP command line?

Looking at your reply to Zoredache, your real problem is not output to the parallel port, that's trivial.
Your real problem is how to get a 0xff character on stdout. This is possible with a trivial .com executable which invokes the relevant soft interrupt, but to be honest it's probably easier to create a file with that single 0xff character in it and then just copy that to the printer:
> copy /b data.bin lpt1
Note the /b flag which tells copy that the file is a binary file.

Back in the DOS days we would frequently use a command like type filename.txt > lpt1 to print our text files.

Related

batch redirect stdin and stdout using start command

I tried to start a exe (jtag console) from a batch file and feed the data from a file to it. This worked well with:
nios2-terminal.exe < test.txt
But there are null chars (0x00) in this file. The chars after the null chars are not passed to the exe, just more zeros, probably because of null terminated strings.
So I splitted the file in 4 files where just the last char is a null and feeded them one after another. The problem is I have to kill the processes, because they wont do it thereself. I need to use the start command.
But I don't know how to feed the file not to the start command but to the exe. This does probably the first:
start /d %path% nios2-terminal.exe < test0.txt
ping 1.1.1.1 -n 1 -w 1 > nul REM// 1ms delay, tried more, too
taskkill /f /im nios2-terminal.exe
start /d %path% nios2-terminal.exe < test1.txt ...
As nios2-terminal.exe puts all chars from stdIn to the jtag of my FPGA, I thougth to use start /b /d %path% nios2-terminal.exe and then read all the files with type testx.txt.
When I do this manualy, I have to press Return first and then the first char I type is put on jtag. In a script I don get this working.
Is ther any other posibility like sending input to the running instance of nios2-terminal.exe or some alternative for the JTAG terminal nios2-terminal.exe, which doesn't mind NULL char inputs.
I hope I didn't missed any threat that allready covers this issue, but I found none.
Thanks a lot
edit:
The title says stdin and stdout redirect because I also want to redirect the output of the program to a file. But I think once I got how to redirect the input with the start command, I can handle this, too.
try this:
nios2-terminal.exe > test.txt
and if you want to append use this cmd:
nios2-terminal.exe >> test.txt

echo with pipe in sh script creates filename with "?"

I'm confronted with a rather strange problem an echo command causes in a script.
It's supposed to be really REALLY basic stuff, but still, there's something "off".
Suppose, I have this script:
#!/bin/bash
# SERVERPID='cat lite_server_pid.txt'
# kill -9 $SERVERPID
nohup java -Xmx3G -Xms2G -jar tekkit_lite_065.jar nogui > output.txt &
echo $! > lite_server_pid.txt
Yes, this starts my own little Minecraft/Tekkit-Server. ;-)
The Problem is, the file thats created is (for some reason) named
lite_server_pid.txt?
and YES, this includes the "?"! Doing the same command in shell, a file without ? is correctly created! Also, the content of the file is the desired processID.
Still, the ? following the filename is a major problem...
What am I doing wrong?
Check your file for DOS line endings. I suspect that ? is actually your terminal's attempt to display a carriage return (\r). Since bash expects UNIX-style newlines, the carriage return part of the DOS newline (\r\n) is treated as a legal character for the file name.
Run your script through dos2unix.

Pass clipboard to batch in Windows XP

Using Windows XP I want to copy text (URL) to the clipboard and then run a batch file that will use that URL.
I know the reverse is possible with the clip.exe floating around.
I use my own CLIPTEXT program. It is a very simple 5-lines pascal, here is the source code. I am sure that you can get the idea and translate it to any other language.
program cliptext;
uses clipbrd;
begin
writeln(clipboard.asText);
end.
then, in your batch files, you may use to start the copied URLs.
for /f "tokens=*" %%c in ('cliptext') do start "" "%%c"

Best automation scripting for command line commands in Windows?

I need to make a script that automates the following:
Read comma or tab separated values from the input file
Construct a command from them and run it
Get the command output, looks for substrings in it and update the log file based on the existence of a substring
I do this in Windows Server 2008, so I can do this in CMD or PowerShell but I am not sure they provide such possibilities. I can try Perl or C#, but I want to try a minimalistic approach first.
Minimalistic as far as coding - Perl
Minimalistic as far as installing new software - PowerShell (IIRS W.S.2008 included that?)
So many answers, and none providing a solution that would meet the requirements...
You didn't say what are the conditions to be checked against each CSV row, and what the CSV would be like, and what the log would be like - so I made it all up... Here's an example in BATCH:
#echo off
set csvfile=input.csv
set logfile=output.log
for /F "tokens=1,2,3 delims=," %%a in (%csvfile%) do call :processline "%%a" "%%b" "%%c"
exit /B 0
:processline
set param=%~3
set check=%param:um=%
rem if they are not equal - substring 'um' exists in it.
if not "$%check%" == "$%param%" (
rem this passes all params to output.
rem I'm not calling echo directly here, because there might be symbols, that will confuse CMD at the end of the %*.
call :output %*>> %logfile%
)
exit /B 0
:output
set colA=%~1
set colB=%~2
set colC=%~3
rem output to log
echo [%DATE% %TIME%] (%colB%) %colA% %colC%.
exit /B 0
Here's the example input file that I tested it with:
foo,1,dum
bar,3,dim
baz,15,dirum
And here's the resulting log messages:
[2009-10-14 14:57:35.87] (1) foo dum.
[2009-10-14 14:57:35.89] (15) baz dirum.
I hope this shows clearly, that BATCH is not nasty nor it is hard to use. :P
If you have further question about BATCH - don't be shy, post them all on SO. ;)
I would recommend going with Python (or Perl if you swing that way). These are very minimal tools to have to install on a machine and add all the functionality you need.
The string handling you describe is unpleasant in any shell (Bash included) unless you are using sed or awk... and that just gets esoteric. In the end you'll retain more hair if you go straight to a scripting language first.
Perl was called into existence to quickly solve these kind
of tasks. It should not take more 20 lines for this
particular problem.
It is also really easy to install:
Download ActivePerl (17.7 MB, Perl 5.10.)
Run the installer.

windows cmd pipe not unicode even with /U switch

I have a little c# console program that outputs some text using Console.WriteLine. I then pipe this output into a textfile like:
c:myprogram > textfile.txt
However, the file is always an ansi text file, even when I start cmd with the /u switch.
cmd /? says about the /u switch:
/U Causes the output of internal
commands to a pipe or file to be Unicode
And it indeed makes a difference, when I do an
c:echo "foo" > text.txt
the text.txt is unicode (without BOM)
I wonder why piping the output of my console program into a new file does not create an unicode file likewise and how i could change that?
I just use Windows Power Shell (which produces a unicode file with correct BOM), but I'd still like to know how to do it with cmd.
Thanks!
The /U switch, as the documentation says, affects whether internal commands generate Unicode output. Your program is not one of cmd.exe's internal commands, so the /U option does not affect it.
To create a Unicode text file, you need to make sure your program is generating Unicode text.
Even that may not be enough, though. I came across this blog from Junfeng Zhang describing how to write Unicode text in a console program. It checks the file type of the standard output handle. For character files (a console or LPT port), it calls WriteFileW. For all other types of handles (including disk files and pipes), it converts the output string to the console's current code page. I'm afraid I don't know how that translates into .Net terms, though.
I had a look how mscorlib implements Console.WriteLine, and it seems to decide on which text output encoding to use based on a call to GetConsoleOutPutCP. So I'm guessing (but have not yet confimed) that the codepage returned is a differnt one for a PS console than for a cmd console so that my program indeed only outputs ansi when running from cmd.