Using Command Prompt in UI Path StudioX

Hi All,

Can anyone guide on what are the best practices and steps to work with with windows command prompt in studiox, Appreciate your help.

Thanks
Mayur

Hi @mayur.jadhav

Welcome to the community,
When working with Windows Command Prompt in StudioX, here are some best practices and steps to follow:

  1. Open the Command Prompt activity: In StudioX, you can open the Command Prompt activity by searching for it in the activities panel.
  2. Enter the command: Once the Command Prompt activity is added to your workflow, you can enter the command you want to run in the “Command” field. You can also pass arguments to the command if necessary.
  3. Configure the options: The Command Prompt activity has several options that you can configure, such as the working directory, timeout, and output encoding. Make sure to configure these options based on your specific needs.
  4. Run the command: Once you have configured the Command Prompt activity, you can run the command by clicking the “Run” button or by using a trigger.
  5. Check the output: After the command has finished running, you can check the output in the “Output” field. You can also use the “Output Encoding” option to change the encoding of the output if necessary.
  6. Handle errors: If the command fails to run or produces an error, you can use the “OnError” option to handle the error and perform some recovery actions, such as retrying the command or notifying someone about the error.

Overall, it is important to carefully design and test your Command Prompt workflows to ensure that they are reliable and produce the desired results. It is also recommended to use error handling and logging mechanisms to track the execution of your workflows and troubleshoot issues when they occur.

Regards,
Vasanth kumar

Hi Vasanth,

as per step 1 I could not find the command prompt activity in studio x. can you please assist.

Thansk
Mayur

@mayur.jadhav

Welcome to the community

I dont think there is a cmd activity as such…as mentioned above

You can sue Use Application/Browser and pass the bat file directly to run the file in cmd…

image

It is not advised to use ui activities on command prompt

hope this helps

cheers

Hi Anil,

Thank you, but with above steps am unable to run batch file, also when i execute a command i need to wait until the command is finished so how do i make sure the run is completed is there a way to read value from cmd and validate in studio x.

appreciate your help.

thanks
Mayur

@mayur.jadhav

Ideally you should be able to do it…I tried it from my end…you can change the use application options in properties for close to never and also include a echo or pause and check it should show you cmd…

From the cmd windows its difficult to identify…as a work around you can use a script to add value failed or success to a text file in the batch script and then read the text file to know the outcome…

You can check text file in a loop if the batch script takes so much time to check the text file in every time interval

Hope this helps

Cheers

A better way than the Use Application activity would be to run cmd from the Invoke Powershell activity.

To do this, the format to use is:
cmd.exe \c "your cmd command here"

In this example, I’m running the cmd command dir and writing it to a text file:

The benefit of this method is that you don’t have to use a UI window at all. If you did, you’d need to poll it to figure out if the command is finished, which is less robust.

Hi Ethan,

Thank you ! but this ask is for studio x platform which do not have the cmd or invoke PowerShell activity.

Thanks
Mayur

Hi Anil,

Thanks much, I could run the batch file and execute the commands as next steps to capture the cmd output if its completed or not as you recommended i have created a script which will write success or error post completion.
Now the challenge is in order to implement the loop logic (Check if the text file has value success if yes exit the loop or else wait 20 sec and check again)
I could not find for loop or while loop activity in studio x can you recommend any alternate way to achieve this loop logic.

I highly appreciate your help with this.

Thanks
Mayur

@mayur.jadhav

You can use a for each with number of times as 50 or so…and inside that use the condition to end the loop if success else wait for 20 seonds…so effectively it check for 20 seconds and maximum of 50 loops

Hope this helps

cheers

In StudioX, I’d treat Command Prompt as a helper, not the main automation layer. It’s useful for simple file operations, scripts, environment checks, or triggering external tools, but I’d avoid building the whole workflow around fragile command-line steps unless there’s no better activity available.

Best practice is usually:

  • use official UiPath activities first
  • use CMD only for stable commands
  • avoid hardcoded paths where possible
  • capture the output/error text
  • add timeout handling
  • test with the same user permissions the robot will run under

A lot of issues come from commands working manually but failing in automation because of permissions, working directory, or missing environment variables.

This is similar to what I’ve heard from SalesAR around lead gen for IT and SaaS systems: automation is strongest when the process is structured and repeatable, not when it depends on hidden manual assumptions.

So yes, CMD can be useful in StudioX — just keep it controlled, logged, and easy to troubleshoot.

Hi @mayur.jadhav

In StudioX, working with Command Prompt is usually done through simple activities or by calling commands directly

The easiest way is to use the Start Process activity and pass cmd.exe as the file name, then give your command in the arguments (for example /c dir or any script you want to run). If you want to capture output, it’s better to use activities like Invoke PowerShell or run a .bat file and read the result from a text file. Keep your commands simple, avoid interactive prompts, and always handle errors (like checking exit codes or output).