XRun not working with batch files

Hi,

I have a problem with XRun. It works to open any app, but for some reason it’s not working with the Command Prompt, so it means I’m unable to run batch files.

There are no errors, the log says that the macro completed successfully and I can even see some “cmd” instances appearing under the Chrome process in the task manager when I run it, but the batch file is finally not run.

I tried to put a wrong path to XRun and then I have an error. So it looks that XRun is finding the file, but for some reason it’s not executing or so.

Can you give me any help?

Thank you very much.

Hi, as a test, can you try with a VBS file instead of batch file?

I tested with V6.31 and all works fine:

Batch file:

rem test
echo "Hello World" 
set arg1=%1
set arg2=%2

echo "Lets do a multiplication" 
set /A myerrorlevel = %arg2% * %arg1%

echo %myerrorlevel%

rem pause
EXIT /B %myerrorlevel%

Macro:

{
  "Name": "batch",
  "CreationDate": "2021-12-21",
  "Commands": [
    {
      "Command": "echo",
      "Target": "start",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "XRunAndWait",
      "Target": "C:\\tst1\\v1.vbs",
      "Value": "8",
      "Description": "Works!"
    },
    {
      "Command": "comment",
      "Target": "XRunAndWait // C:\\tst1\\test.bat",
      "Value": "8 881",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Done, exit code is ${!xrun_exitcode}",
      "Value": "green",
      "Description": ""
    }
  ]
}

Hi, thanks for the answer. I was able to reproduce your examples and receive the same exit codes.

I tried to upload a video showing my problem but I’m not allowed, so let me explain.

Let’s say I create a batch file like this:

del ttt.txt

EXIT /B 5555

If I execute this batch file, the “ttt.txt” is normally deleted. However, if I try to run this same batch file using XRun, the macro will complete normally, the exit code “5555” will show in the UI.Vision log, but the “ttt.txt” file is not deleted.

Any ideas of what is the problem?

I confirmed the issue, I assume this is a permission issue, because if you start the batch file, it runs as your user. But if the RPA software starts it, it runs with the reduced permissions of the web browser (that is where the RPA core “lives” as extension. So with a batch file it seems no file operation works, not even rename or copy.

Solution: Use a VBS script instead. Everything works there! I tested with this script:

' VBScript
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")

FSO.CopyFile "c:\test\ttt.txt", "c:\test\justacopy.txt"

FSO.DeleteFile "c:\test\ttt.txt"

WScript.Quit 123

I suspect it is not a permission issue: previously I was having problems to control some apps, my clicks and keystrokes were not working, I even tried different RPA solutions and it was always the same. At some point I found out that the apps that I was trying to control were executed as administrator, so when I ran Chrome as administrator too, everything started working. On the other hand, XRun with batch files still not work even running Chrome as admin.

The batch I commented before was just an example to reproduce the problem. What I really need to do is to use the Command Prompt to run a Powershell file, that will send an email. It’s a single line batch file:
powershell -executionpolicy remotesigned -File %cd%\email.ps1

Any idea to make this work?

You can start Powershell scripts directly from XRunAndWait:

See here:

PS1 Script:

$param1=$args[0]
write-host $param1 

$param2=$args[1]
write-host $param2

$r = [int]$param1 * [int]$param2

exit $r

Macro:

{
  "Name": "ps1",
  "CreationDate": "2021-12-22",
  "Commands": [
    {
      "Command": "echo",
      "Target": "start",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "XRunAndWait",
      "Target": "powershell.exe",
      "Value": " -ExecutionPolicy Bypass -File \"C:\\tst1\\test.ps1\" 8 33",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Done, exit code is ${!xrun_exitcode}",
      "Value": "green",
      "Description": ""
    }
  ]
}

See also:

2 Likes

I tested and it worked, thanks!!

1 Like