• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Export error code when using app.system to run a command on Windows

Explorer ,
Sep 10, 2021 Sep 10, 2021

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.

TOPICS
Actions and scripting

Views

400

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 10, 2021 Sep 10, 2021

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;

 

Votes

Translate

Translate
Adobe
LEGEND ,
Sep 10, 2021 Sep 10, 2021

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()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

hui5C21_0-1631263318999.png

seems format is not all right

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

When you edit .bat file on your desktop is the message wrote in right language?

 

Maybe avoid decodeURI.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

I mean the quotation seems not right

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 10, 2021 Sep 10, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 10, 2021 Sep 10, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

Post your solution then - that might be helpful in the future for others 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 10, 2021 Sep 10, 2021

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' )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 10, 2021 Sep 10, 2021

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;

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

excellent solution. It works Perfect.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 10, 2021 Sep 10, 2021

Copy link to clipboard

Copied

LATEST

Thank you so much!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines