-3

"C:\Users\AppData\Local\UiPath\app-19.7.0\UiRobot.exe" /file "C:\Users\Documents\UiPath\ThirdProcess\Main.xaml"

I need to execute this script from CMD only, as I am doing other API creation in my python code.

I am expecting to run one RPA bot using this script execution and then I will perform other data fetching task from the python API code.

shubham jain
  • 45
  • 11
  • First use [os.environ.get or os.getenv](https://docs.python.org/3/library/os.html) to get string value of [Windows environment variable](https://en.wikipedia.org/wiki/Environment_variable#Windows) `LOCALAPPDATA` which holds the path to local application data path of current user. I doubt that there is really `C:\Users\AppData\Local\UiPath\app-19.7.0\UiRobot.exe` as the account name is missing in this path. Concatenate this string with `\UiPath\app-19.7.0\UiRobot.exe` to get full qualified file name of the executable to run. – Mofi Jul 20 '19 at 07:35
  • Next use again `os.getenv` to get string value of Windows environment variable `USERPROFILE` and concatenate it with string `\Documents\UiPath\ThirdProcess\Main.xaml` to get full qualified file name of the XAML file. Next use [os.path.isfile](https://docs.python.org/3/library/os.path.html) two times with both file names to verify if the executable and the XAML file really exist. Then use [subprocess](https://docs.python.org/3/library/subprocess.html) module to run the executable with the XAML file as argument. – Mofi Jul 20 '19 at 07:41
  • If you think reading Python documentation is not worth the time (which is definitely not true), you can find related questions and answers for the few lines of Python code for this task also on Stack Overflow. See for example [How to access environment variable values?](https://stackoverflow.com/questions/4906977/), [How do I check whether a file exists without exceptions?](https://stackoverflow.com/questions/82831/) [Python subprocess call with arguments having multiple quotations](https://stackoverflow.com/questions/8581140/). – Mofi Jul 20 '19 at 07:47
  • @Mofi , yes Agree with you on above points, I need to think first to build or finalize an approach for any problems. new in python and stack-overflow , now will make such habits. thank you . and yes I do find difficultly in understanding Python officially documentation. – shubham jain Jul 22 '19 at 14:01

2 Answers2

0

I'm not entirely sure what you're trying to do with these programs, but it looks like you could use Popen. There's a similar post here if you want to look at it.

import subprocess
myCmd = "C:\Users\AppData\Local\UiPath\app-19.7.0\UiRobot.exe"
subprocess.Popen(myCmd)

and if you had multiple commands you could loop through a list

import subprocess
myCmds = ["C:\Users\AppData\Local\UiPath\app-19.7.0\UiRobot.exe", "C:\Users\Documents\UiPath\ThirdProcess\Main.xaml"]
for Cmd in myCmds:
    subprocess.Popen(Cmd)
Isaiah
  • 103
  • 11
  • Hi @Isaiah, yes I need to use Popen of subprocess module. but this below script is not working for me, I need to pass all 3 piece of code in single line to commad prompt. to run one .exe file with file location as a arg. please help me here import subprocess subprocess.popen(["C:\Users\AppData\Local\UiPath\app-19.7.0\UiRobot.exe", "/file", "C:\Users\Documents\UiPath\ThirdProcess\Main.xaml"]) this one line is working fine in Command prompt:- "C:\Users\AppData\Local\UiPath\app-19.7.0\UiRobot.exe" /file "C:\Users\Documents\UiPath\ThirdProcess\Main.xaml" – shubham jain Jul 19 '19 at 11:09
  • I'm not sure how to add the /file in python But You might be able to make a batch file and launch it through python https://www.makeuseof.com/tag/launch-multiple-programs-single-shortcut-using-batch-file/ or a shortcut with the /file argument – Isaiah Jul 19 '19 at 15:07
0

Below code helped me to achieve this functionality.

subprocess.call([
    'C:\\Users\\shubham\\AppData\\Local\\UiPath\\app-19.7.0\\UiRobot.exe',
    '/file',
    'C:\\Users\\shubham\\Desktop\\FinalOCR\\InvoiceAutomation\\PDFReadwithNative.xaml'
])

Thank you everyone.

Mofi
  • 46,139
  • 17
  • 80
  • 143
shubham jain
  • 45
  • 11