Copy link to clipboard
Copied
Hi~:
I use .jsx file to run a python script like this ( app.system("python3 \"C:/" + decodeURI(env.scriptFileDirectory).substring(3) + "\\robot.py\" \"" + msg) ). this msg param contains chinese, but export error code. I believe that's because windows cmd using CP936 code but my script using utf-8, what can i do with this problem??
I can work with Nodejs to deal with this, but not with jsx.
Thanks so much.
Now I kept your styles of quotation marks, just added first line:
txt = "chcp 936\rpython3 \"C:/" + decodeURI(env.scriptFileDirectory).substring(3) + "\\robot.py\" \"" + msg;
Copy link to clipboard
Copied
Maybe that will work if I wrote it as should:
txt = 'chcp 936\r"' + 'python3 "C:/' + decodeURI(env.scriptFileDirectory).substring(3) + '\\robot.py" "' + msg;
(sys = File('~/Desktop/sys.bat')).open('w'), sys.write(txt), sys.close(), sys.execute()
Copy link to clipboard
Copied
seems format is not all right
Copy link to clipboard
Copied
When you edit .bat file on your desktop is the message wrote in right language?
Maybe avoid decodeURI.
Copy link to clipboard
Copied
I mean the quotation seems not right
Copy link to clipboard
Copied
Regarding quotation marks I didn't focus on this too much so there might be some mistakes. It's on your side to use them properly. I only suggested if you need right language you must use in the .bat file in the first line encoding marker.
Copy link to clipboard
Copied
I used a complex way to solved this problem. I wrote the msg to a file with encoding utf-8, the pass the file path to python and read the file in python scripts.
Copy link to clipboard
Copied
Post your solution then - that might be helpful in the future for others 😉
Copy link to clipboard
Copied
function sendAlert( msg )
{
if ( env.scriptFileDirectory ) {
writeMsg( msg )
var cmd = "python \"C:/" + decodeURI(env.scriptFileDirectory).substring(3) + "\\DDRobot.py\" " + msg.replace(/ /g,"_") + " \"" + getPath( expFolder ) + "/msg.txt\""
app.system(cmd)
}
}
function getPath( folder )
{
return decodeURI(folder.path).replace( /\/c\//g,'C:/' ).replace( /\/d\//g,'D:/' ).replace( /\/e\//g,'E:/' )
.replace( /\/f\//g,'F:/' ).replace( /\/g\//g,'G:/' )
}
function writeMsg( msg )
{
var f = new File( expFolder.path + "/msg.txt" )
f.open("w")
f.encoding = "UTF-8"
f.writeln( msg )
f.close()
}
sendAlert( 'alert' )
Copy link to clipboard
Copied
Now I kept your styles of quotation marks, just added first line:
txt = "chcp 936\rpython3 \"C:/" + decodeURI(env.scriptFileDirectory).substring(3) + "\\robot.py\" \"" + msg;
Copy link to clipboard
Copied
excellent solution. It works Perfect.
Copy link to clipboard
Copied
Thank you so much!