Tutorials & Examples Web-help Blog

Run a .BAT file


I want to use the run program action to launch a .bat file. I have an error
Error: External program failed with exit code 1; path=C:\data\job\Google_Analytics_Export_0.1\Google_Analytics_Export\Google_Analytics_Export_run.bat; args=; workdir=
Source: Action “Run program” in table “Table 1” in project “C:\data\easymorph\run_ga_extract.morph”

can you help me ?


Hi Thomas,

Exit code 1 usually means that bat file (or one of the programs, called by that bat file) failed for some reason.

You can try to turn on “Capture output” option of “Run program” action. It’s possible that it will show you an error message.


Thx ! i had the clue in the error captured. the environnement variable was not set for java.



I am trying to run a .bat file in the run a program action but it does not work. The action keeps running.

In my cmd prompt it runs correctly.Could you help me out? Is there another way to do this ?
The bat file contains psql syntax for log in to a database.

What I am trying to achieve is that I can log on to a postgresql database and then, that I can run the \copy from command so that I can import big CSV-files into the database. I have to do it this wat because the normal COPY FOM SQL-variant is not allowed on the RDS instance on Amazon.
So my question is how I can create a script to log in to the database, execute the copy from command for a table (or multiple tables) and execute that script from within easyMorph?


Hi Nikolaas,

It’s possible, that your bat file is waiting for user input. In such case “Run program” action will run indefinitely. You can try to turn on “Capture output” option - it worked for me with a simple example.

As for running psql from EasyMorph - you can just run psql from “Run program” action with appropriate command line arguments. Commands can be defined in a separate text file and passed to psql with -f or --file argument. But it shouldn’t make a significant difference in your case.


Hi Andrew,

Could you post a screenshot of how I can do this because I do not understand it 100 %?

Do I need to run the psql shell or the command prompt ?

Thanks !


Nikolaas, something like this:

It seems that psql prompts for a password even when “Capture output” option of “Run program” action is checked. So you’ll have to pass --no-password argument to psql in order to suppress that prompt and then choose another way to pass your password to psql.

Please refer to psql documentation and StackOverflow questions for information about psql command line arguments and possible ways of passing a password.


Thanks Andrew

I have the same kind of problem. We will try to find a workaround.

I suppose that a \copy cannot be executed in the database command action ?


Nikolaas, yes, \copy is not an SQL command, so it can’t be executed with database command action.


Hi Andrew,

I have been testing this. On the server where EaysMorph is installed and where we also have pgsql.exe I can run it from the command line directly with the following command (I replaced here the host with myhost so that I can post it on the forum).

cd C:\Program Files\PostgreSQL\11\bin

psql --host=myhost --dbname=energieprestatiedatabank --username=easymorph_user --no-password --file=“D:\EasyMorph_Server\Spaces\development\gebouwen\load.sql”

When I try to run it like this in run a program it does not import the CSV. In the load.sql file there’s a \copy command.

When I try another approach by pointing to the application directly from run a program it does not work either. I override parameters on the server to make sure I refer to the right programs and files.


Nikolaas, does “Run program” runs indefinitely in the Desktop version or issues an errors?

Have you tried “Run program” action with checked “Capture output” option?


I will send you more details by mail.