I'm using cp 932 and trying to get the output as i scripted:
#echo off
chcp 932
cls
echo a i u e o-ka ki ku ke ko-sa shi su se so-ta chi tsu te to-ha hi fu he ho-ma mi mu me mo-ya yu yo-ra ri ru re ro-wa wo n
echo.
echo あいうえお きかくけこ さしすせそ たちつてと なにぬねの はひふへほ まみむめも やゆよ らりるれろ わをん
echo.
echo アイウエオ カキクケコ サシスセソ タチツテト ナニヌネノ ハヒフヘホ マミムメモ ヤユヨ ラリルレロ ワヲン
pause>nul
but i get the following output:
a i u e o-ka ki ku ke ko-sa shi su se so-ta chi tsu te to-ha hi fu he
ho-ma mi mu me mo-ya yu yo-ra ri ru re ro-wa wo n
縺ゅ>縺・∴縺翫縺阪°縺上¢縺薙縺輔@縺吶○縺昴縺溘■縺、縺ヲ縺ィ縲縺ェ縺ォ縺ャ縺ュ縺ョ縲縺ッ縺イ縺オ縺ク縺サ縲縺セ縺ソ繧繧√b縲繧・f繧医繧峨j繧九l繧阪繧上r繧・
繧「繧、繧ヲ繧ィ繧ェ縲繧ォ繧ュ繧ッ繧ア繧ウ縲繧オ繧キ繧ケ繧サ繧ス縲繧ソ繝√ヤ繝・ヨ縲繝翫ル繝後ロ繝弱繝上ヲ繝輔・繝帙繝槭Α繝繝。繝「縲繝、繝ヲ繝ィ縲繝ゥ繝ェ繝ォ繝ャ繝ュ縲繝ッ繝イ繝ウ
How to display the right characters?
There is no problem. As you can see, I'm on (Central European) Windows with Latin script:
You need to save the script using right encoding:
Moreover, Windows itself switch to right font (my default cmd font is set to Courier New with no CJK script):
You can convert text to Base64 and Decode it in Vbscript to show text.
Save whole code bellow as a .vbs and run it.(Don't run it via cscript or wscript).
Try my way :
Str="44GC44GE44GG44GI44GK44CA44GN44GL44GP44GR44GT44CA44GV44GX44GZ44Gb44Gd44CA44Gf44Gh44Gk44Gm44Go44CA44Gq44Gr44Gs44Gt44Gu44CA44Gv44Gy44G144G444G744CA44G+44G/44KA44KB44KC44CA44KE44KG44KI44CA44KJ44KK44KL44KM44KN44CA44KP44KS44KT"
St="44Ki44Kk44Km44Ko44Kq44CA44Kr44Kt44Kv44Kx44Kz44CA44K144K344K544K744K944CA44K/44OB44OE44OG44OI44CA44OK44OL44OM44ON44OO44CA44OP44OS44OV44OY44Ob44CA44Oe44Of44Og44Oh44Oi44CA44Ok44Om44Oo44CA44Op44Oq44Or44Os44Ot44CA44Ov44Oy44Oz"
'===========================================================================
Function Base64Decode(ByVal vCode)
Set oNode = CreateObject("Msxml2.DOMDocument.3.0").CreateElement("base64")
oNode.dataType = "bin.base64"
oNode.text = vCode
Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue)
Set oNode = Nothing
End Function
Function Stream_BinaryToString(Binary)
Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Type = 1
BinaryStream.Open
BinaryStream.Write Binary
BinaryStream.Position = 0
BinaryStream.Type = 2
BinaryStream.CharSet = "utf-8"
Stream_BinaryToString = BinaryStream.ReadText
Set BinaryStream = Nothing
End Function
WSH.Echo "a i u e o-ka ki ku ke ko-sa shi su se so-ta chi tsu te to-ha hi fu he ho-ma mi mu me mo-ya yu yo-ra ri ru re ro-wa wo n"&vblf&Vblf&Base64Decode(Str)&vblf&Vblf&Base64Decode(St)
Related
I have just com across https://github.com/google/guetzli - And would like to write a script to run it on all jpeg images in a project on windows.
How would I loop though, all files in the folder and sub folder and get the relative paths to input into the command? Finally as guetzli is reasonably slow is there a way to wait for the execution to finish or put a delay in?
Thanks,
Lewis
For anyone interested, this is the code I went for;
setlocal disableDelayedExpansion
for /f "delims=" %%A in ('forfiles /s /m *.jpg /c "cmd /c echo #relpath"') do
(
set "file=%%~A"
setlocal enableDelayedExpansion
echo !file:~2!
CALL "guetzli.exe" --quality 85 !file:~2! !file:~2!
endlocal
)
Just put it into put it into the root directory with the guetzli executable
I just had to do this, and wrote these simple few lines of Python to handle it. No attempt here to be super-Pythonic. Only numeric jpgs is specific to the folder I was handling. Had to use quality=95 because of compression artifacts on very light skin tones still noticeable at 90. Still went from 6.4meg to 2.2meg for 25 420x280 jpg images (originals were max quality). At qual=85 size was 1.7meg, so 0.5meg for noticeable reduction in artifacts is acceptable. Stil big savings - Guetzli is great. HTH. -Steve
import os
import time
import subprocess
files = os.listdir('./')
jpgs = []
for file in files:
if file[len(file)-3:] != 'jpg':
continue
try:
fnum = int(file.split('.')[0])
except:
continue
jpgs.append(file)
jpgs.sort()
todo = len(jpgs)
done = 1
print '# %d = todo' % (todo)
start_tot = time.time()
for jpg in jpgs:
fnum = int(jpg.split('.')[0])
cmd = 'guetzli --quality 95 %d.jpg %d_g.jpg' % (fnum, fnum)
print '# %d of %d' % (done, todo)
print '# %s' % (cmd)
start_img = time.time()
subprocess.call(cmd, shell=True)
t_this = time.time() - start_img
t_tot = (time.time() - start_tot)
avg = t_tot / float(done)
done += 1
print '#---%d done: %0.2f sec, %0.2f avgSec, %0.2f minTot' % ( fnum, t_this, avg, t_tot/60.0)
#end
I'm working on a script to automatically configure Nodemanager, enroll a machine and starting de managed servers in it. What i currently have is (not exactly):
connect(...)
cd('/')
for m in cmo.getMachines():
nombre_machine=m.getName()
#Solo ejecutamos el NodeManager en el que estamos ejecutando el script.
if nombre_machine in HOST:
cd('/Machines/'+nombre_machine+'/NodeManager/'+nombre_machine)
machine=cmo
nm_srv_addrs[machine.getListenPort()] = machine.getListenAddress()
for nm_port, nm_addr in nm_srv_addrs.iteritems():
printInStyle('Iniciando Nodemanager, favor tener paciencia la primera vez.')
startNodeManager(verbose='false', NodeManagerHome=NM_HOME, ListenPort=str(nm_port), ListenAddress=nm_addr)
print 'Generando nodemanager.properties ',
while not os.path.exists(NM_PROP_FILE):
systime.sleep(10)
print '\b.',
sys.stdout.flush()
print 'Archivo creado!'
cd('/')
servidores = cmo.getServers()
for s in servidores:
nombre = s.getName()
if nombre != 'AdminServer':
start(nombre)
But the last sequence will fail because will try to start all servers and i'm looking to start only the in the one i'm running the script.
What i believe i'm looking is a way to filter the servers in the current machine.
I'll appreciate any help or advice. I am just starting in wlst scripting.
thanks
I figured it out thanks to this link
I'll just need to filter in a couple of loops like this:
import os
cd('/')
current_m=''
machines = cmo.getMachines()
for m in machines:
hostname = os.environ['HOSTNAME']
nm = m.getNodeManager()
if nm.getListenAddress() in hostname:
current_m=m
servers = cmo.getServers()
for s in servers:
name = s.getName()
if name != 'AdminServer':
ref = getMBean('/Servers/'+name+'/Machine/'+current_m.getName())
if ref != None:
start(name)
I'm currently working on a program that can start other Programs. Its in batch. But i need it to be user friendly. I want a code that can open a file select window, and save the directory of what i selected into a txt file (or csv or whatever). I'm new on VBS so forgive me if I'm missing something simple. But i searched for a while and got close, only to fail.
Here's what i have so far...
Set shell = CreateObject( "WScript.Shell" )
defaultLocalDir = shell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop"
Set shell = Nothing
file = ChooseFile(defaultLocalDir)
wscript.echo file
Function ChooseFile (ByVal initialDir)
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
Dim winVersion
' This collection should contain just the one item
For Each objItem in colItems
'Caption e.g. Microsoft Windows 7 Professional
'Name e.g. Microsoft Windows 7 Professional |C:\windows|...
'OSType e.g. 18 / OSArchitecture e.g 64-bit
'Version e.g 6.1.7601 / BuildNumber e.g 7601
winVersion = CInt(Left(objItem.version, 1))
Next
Set objWMIService = Nothing
Set colItems = Nothing
If (winVersion <= 5) Then
' Then we are running XP and can use the original mechanism
Set cd = CreateObject("UserAccounts.CommonDialog")
cd.InitialDir = initialDir
cd.Filter = "ZIP files|*.zip|Text Documents|*.txt|Shell Scripts|*.*sh|All Files|*.*"
' filter index 4 would show all files by default
' filter index 1 would show zip files by default
cd.FilterIndex = 1
If cd.ShowOpen = True Then
ChooseFile = cd.FileName
Else
ChooseFile = ""
End If
Set cd = Nothing
Else
' We are running Windows 7 or later
Set shell = CreateObject( "WScript.Shell" )
Set ex = shell.Exec( "mshta.exe ""about: <input type=file id=X><script>X.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(X.value);close();resizeTo(0,0);</script>""" )
ChooseFile = Replace( ex.StdOut.ReadAll, vbCRLF, "" )
Set ex = Nothing
Set shell = Nothing
End If
End Function
Maybe you are looking for something like next bat code snippet?
#echo OFF
SETLOCAL enableextensions
set "_chosen="
if exist "_saved.txt" (
rem read previously saved value
<"_saved.txt" set /P "_chosen="
echo read previously saved value
) else (
for /f "delims=" %%G in ('
cscript //NOLOGO "D:\VB_scripts\SO\31656148.vbs"
') do (
set "_chosen=%%G"
rem save value to a file
>"_saved.txt" echo(%%G
echo file chosen, value saved
)
)
if defined _chosen (
echo("%_chosen%"
) else (
echo no file chosen
)
I am working on a small NLP project of authorship attribution: I have some texts from two authors and I want to say who wrote them.
I have some pre-processed text (tokenized, pos-tagged, ect.) and I want to load it into sciki-learn.
The documents have this shape:
Testo - SPN Testo testare+v+indic+pres+nil+1+sing testo+n+m+sing O
: - XPS colon colon+punc O
" - XPO " quotation_mark+punc O
Buongiorno - I buongiorno buongiorno+inter buongiorno+n+m+_ O
a - E a a+prep O
tutti - PP tutto tutto+adj+m+plur+pst+ind tutto+pron+_+m+_+plur+ind O
. <eos> XPS full_stop full_stop+punc O
Ci - PP pro loc+pron+loc+_+3+_+clit pro+pron+accdat+_+1+plur+clit O
sarebbe - VI essere essere+v+cond+pres+nil+2+sing O
molto - B molto molto+adj+m+sing+pst+ind
So it's a tab separeted text file of 6 columns (word, end of sentence marker, part of speech, lemma, morphological information and named entity recognition marker).
Every file represents a document to classify.
What would be the best way to shape them for scikit learn?
The structure they use in scikit-learn example https://scikit-learn.org/stable/tutorial/text_analytics/working_with_text_data.html# is described here
http://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_files.html
Replace this
# Load some categories from the training set
if opts.all_categories:
categories = None
else:
categories = [
'alt.atheism',
'talk.religion.misc',
'comp.graphics',
'sci.space',
]
if opts.filtered:
remove = ('headers', 'footers', 'quotes')
else:
remove = ()
print("Loading 20 newsgroups dataset for categories:")
print(categories if categories else "all")
data_train = fetch_20newsgroups(subset='train', categories=categories,
shuffle=True, random_state=42,
remove=remove)
data_test = fetch_20newsgroups(subset='test', categories=categories,
shuffle=True, random_state=42,
remove=remove)
with your data load statements, for example:
# Load some categories from the training set
categories = [
'high',
'low',
]
print("loading dataset for categories:")
print(categories if categories else "all")
train_path='c:/Users/username/Documents/SciKit/train'
data_train = load_files(train_path, encoding='latin1')
test_path='c:/Users/username/Documents/SciKit/test'
data_test = load_files(test_path, encoding='latin1')
and in each of train and test directories create "high" and "low" subdirectories for your category files.
My problem is probably a format error but i can't find what error it is, when i use readFile and then I try to read that string into a data type, i receive that error.
I'm implementing a simple interpreter of a programming language in Haskell like this post:
Implementing a language interpreter in haskell
Then, I am trying to read from a file some datatype from user and files, when it is from user, it correctrly works, but not for the types read from file. My datatypes are the following:
infixr 1 :=
infix 4 :<, :>, :==, :>=, :<=
infixl 6 :+, :-
infixl 7 :*, :/
data Valuable = I Int --Entero
| V Variable --Variable
| Valuable :+ Valuable
| Valuable :- Valuable
| Valuable :* Valuable
| Valuable :/ Valuable
deriving (Read, Show);
data Boolval = B Bool --Dato booleano
| Valuable :>= Valuable
| Valuable :<= Valuable
| Valuable :== Valuable
| Valuable :> Valuable
| Valuable :< Valuable
deriving (Read, Show);
data Instruccion = Valuable := Valuable
| While Boolval Instruccion
| Cond Boolval Instruccion
| Varias [Instruccion]
deriving (Read, Show);
And when I'm trying to get the input with this procedure:
mst::[VarVal]->String -- Varval is [String, int]
mst [] = ""
mst[(a,b)] = "('" ++ a ++"', "++ (show b) ++ ")"
mst((a,b):xs) = "('" ++ a ++"', "++ (show b) ++ "), " ++ mst xs
main = do
putStrLn "Introduce el nombre del programa a cargar (Por ejemplo arch.txt)"
file <- getLine --Se toma el nombre de archivo
putStrLn "Introduce el estado de las variables con comillas dobles, (ej [(`X`,3)])"
user_state <- getLine --Se toma la entrada
arch <- readFile file
let real_state = read user_state
let my_program_file = read arch
putStrLn arch
let lst = ejecutar my_program_file real_state --problemas
putStrLn (mst lst)
The problem comes when is used the "read file" instruction, because the input format is not correct(I'm not sure) and i get the message: *** Exception: Prelude.read: no parse. this is the input format
Varias [(V "Y" := (V "X"),
(V "R" := I 1),
(While (I 0 :< V "Y") (Varias [
(V "R" := (V "R" :* V "Y")),
(V "Y" := (V "Y" :- I 1))
])
)
]
What am I doing wrong?