I need to access some files with russian filenames from REXX.
The filenames are listed in a text file.
The code correctly reads the input list of filenames, but when the code invokes an external command using as a parameter the line that has been read, it fails.
The simplified code is
say "SRC" FQO ;
say "DEST" FQD ;
say "CHCP"
CHCP
newCMD = 'XCOPY /Y' FQO FQD
say "CMD" newCMD ;
newCMD
And the displayed result is
SRC C:\prive\$_Родословная.txt
DEST C:\data\
CHCP
Active code page: 65001
CMD XCOPY /Y C:\prive\$_Родословная.txt C:\data\
File not found - $_РодоÑловнаÑ.txt
0 File(s) copied
It seems as if the Rexx Interpreter did not honor the current codepage (65001) for invoking the external NewCMD.
Any clues ?
Related
I am trying to rename files using Windows CMD from file naming data-001.wav data-002.wav to input-001.wav input-002.wav replacing the word data to input in the file names.
I tried: ren data-*.wav input-*.wav but getting input-01.wav input-02.wav instead of input-001.wav input-002.wav the numbering digits are not matching the file names correctly.
I have a directory with over 100 text files.
How can I append the word "END" at the end of every file within that directory?
Follow these steps.
Backup your files.
Go to the relevant directory.
Open CMD from that directory.
Run this command.
for %f in (*.txt) do echo END >> %f
Note:
If your text file encoding is not ANSI, then the result might be different from what you want.
ANSI > This is a test.END
Unicode > This is a test.久⁄
Unicode big endian > This is a test.䕎䐠ഊ
UTF-8 > This is a test.END
You might want to check these links too...
Add a new line to a text file in MS-DOS
How to do something to each file in a directory with a batch script
PowerShell option:
"END" | Add-Content -path *.txt
Add-Content will append the pipeline input to all files matching its parameters (there are other options to include/exclude lists of wildcard patterns).
This is my code:
# -*- coding: utf-8 -*-
import subprocess as sp
import locale
LOCAL_ENCODING = locale.getpreferredencoding()
cmds = ['dir', '/b', '*.txt']
out = sp.check_output(cmds, shell=True)
print(out)
print(out.decode(LOCAL_ENCODING))
s = 'レミリア・スカレート.txt'
print(s.encode(LOCAL_ENCODING, 'replace'))
print(LOCAL_ENCODING)
# print(s.encode('utf-8'))
This is the output:
b'\xa5\xec\xa5\xdf\xa5\xea\xa5\xa2?\xa5\xb9\xa5\xab\xa5\xec\xa9`\xa5\xc8.txt\r\n'
レミリア?スカレート.txt
b'\xa5\xec\xa5\xdf\xa5\xea\xa5\xa2?\xa5\xb9\xa5\xab\xa5\xec\xa9`\xa5\xc8.txt'
cp936
(A text file named 'レミリア・スカレート.txt' is in the script directory.)
As the result shows, the bytes of the file name returned has been automatically encoded by local encoding, which can't totally encode the filename(Note the ? in the bytes), thus some information lost.
Environment:
- win10 Chinese Simplified
- python-3.5.1
My question is:
Is it possible to avoid the automatical local-encoding and get an utf-8(or some other specified encoding) bytes?
I read this issue, but got no solution :-(
1.For built-in command, solved by eryksun's answer:
out = sp.check_output('cmd.exe /u /c "dir /b *.txt"').decode('utf-16le'),
/u: Output UNICODE characters (UCS-2 le),
/c: Run Command and then terminate)
2.For external programs:[no general solution]
configure the output using proper encoding(by setting exteral programs' options or configurations, of course, such options may be nonexistent),
for example, in the latest winrar, one can set the encoding of console rar messages:rar lb -scur data > list.txt, will produce Unicode list.txt with archived file names
I'm creating a batch file and the final part of the batch is to concatenate the text from multiple csv files into one. The csv that is created is correct, however when I run the command it shows the file names on a separate line. Even with echo off it still shows. When I simply copy and paste the line into a blank txt file and use #echo off and that's it.. it still shows the output.
type lak-print01.csv lak-print02.csv lak-print03.csv lak-print04.csv or-sdc-print.csv tac-print01.csv tac-print02.csv tuk-print01.csv wa-02print01.csv wa-110print01.csv wa-61print01.csv > MasterPrinterList.csv
The output shown in cmd line is as follows. I just want it to perform the type command w/o showing the files.
lak-print02.csv
lak-print03.csv
lak-print04.csv
or-sdc-print.csv
tac-print01.csv
tac-print02.csv
tuk-print01.csv
wa-02print01.csv
wa-110print01.csv
wa-61print01.csv
Any help?
Redirect StdErr to nul by appending 2>nul. (type outputs filenames into that.) The command you want is this:
type lak-print01.csv lak-print02.csv lak-print03.csv lak-print04.csv or-sdc-print.csv tac-print01.csv tac-print02.csv tuk-print01.csv wa-02print01.csv wa-110print01.csv wa-61print01.csv > MasterPrinterList.csv 2>nul
type lak-print01.csv lak-print02.csv lak-print03.csv lak-print04.csv or-sdc-print.csv tac-print01.csv tac-print02.csv tuk-print01.csv wa-02print01.csv wa-110print01.csv wa-61print01.csv > MasterPrinterList.csv 2>nul
the file names are printed in error stream so all you need is to add 2>nul at the end.
type also accepts wildcards so you can make your line shorter e.g
type lak*.csv or*.csv tac*.csv wa*.csv > MasterPrinterList.csv 2>nul
Assume a psuedo command:
psuedocmd.exe
It has various parameters like:
/scan /save /savefolder
Now i want to run psuedocmd.exe using batch file.
And i would like to use parameters too.
I am using the following line in batch file
psuedocmd.exe /scan /save
But in this case psuedocmd.exe is running without the parameters.
Try putting parameters between quotes "parameter value", especially if paths have spaces in them.
Check if the batch text file is not saved in some encoding making your / be read as an escape character.
If you want to run the .exe by handing over parameters from the batchfile, don't use variables, just use %1, %2, etc.
run.bat /save /folder
Where run.bat's contents are:
pseudocommand.exe %1 %2
Hehe, after over half a year, I'm out of patience..
You must provide the savefolder parameter when using the save parameter in Acunetix Web Vulnerability Scanner, making that line in your batch-file look like:
wvs_console.exe /scan "http://www.aaa.com" /save /savefolder "c:\log"
Excerpt from the documentation:
/scan Scans a single website.
Syntax: /scan [url]
Example: /scan http://testphp.vulnweb.com
/save Saves scan once scan is finished. The file will be
saved in the location specified by the “/savefolder” switch.
Syntax: /save
/savefolder Specify the folder were all the scans and other
scan related files will be saved.
Syntax: /savefolder [directory]
Example: /savefolder C:\Acunetix\Scans