Page 1 of 1

Calling an external program using a Trigger

Posted: Wed Sep 21, 2011 3:52 am
by akashjain
Firstly, I would like to mention the point that the ProcessMaker has been installed on Linux machine and I am accessing this processmaker account on a Windows machine currently.

I have created a workflow and the aim is to call the basic calculator of Linux to do some calculation in a dynaform.

I have used the following code in the trigger(accessing the account on windows machine):
exec("/usr/bin/bc [-1]");

But on execution of the trigger, nothing seems to happen. Can someone please tell me is it a problem with the syntax or conflict of OS or the method is itself wrong?
And if so, please give a detailed(since I am just a beginner) procedure of how to call an external program using a trigger.

Please reply as soon as possible. My work is really urgent.

Re: Calling an external program using a Trigger

Posted: Wed Sep 21, 2011 4:50 pm
by amosbatto
I suspect that your problem is the [-1] part because you are using a referencer to a file, but that referencer doesn't exist in this context. You need to use a real filename, not a reference. Also, you need to have a second parameter to capture what is returned by the function.

exec("/usr/bin/bc path/somefile", @@ret);

Re: Calling an external program using a Trigger

Posted: Thu Sep 22, 2011 3:44 am
by akashjain
Thanks amosbatto for your prompt help. I would be grateful to you if you can explain in detail the method you have specified by giving an example.

Like if I have three case variables @@part_cost, @@labor_cost and @@miscellaneous_cost and I want to call the linux basic calculator to calculate the sum of values of these variables and return that into @@total_cost (all of these variables being defined in the dynaform), what commands will I have to write in trigger and file(that you specified).

I have tried a lot of times but somehow I am not able to get the required result. Please reply.

Thanks in advance!

Re: Calling an external program using a Trigger

Posted: Thu Sep 22, 2011 5:23 am
by akashjain
Also, I need to know what is the format of 'somefile' (is it .php or .txt ?) and also the path where it has to be stored in order to be recognized by basic calculator.

Re: Calling an external program using a Trigger

Posted: Thu Sep 22, 2011 7:53 pm
by amosbatto
I suggest that you use this trigger code instead:
Code: Select all
@#total_cost = @#part_cost + @#labor_cost + @#miscellaneous_cost;
I have no idea how bc works. All I know is that if I enter "bc [-1]" in the normal command line, Linux says:
$ bc [-1]
File [-1] is unavailable.
So bc is expecting a file. Obviously you are using the command wrong.

Re: Calling an external program using a Trigger

Posted: Thu Dec 15, 2011 5:46 am
by divyladha
Hey AMOS ,

Can a .exe file stored on the server be called using a PM trigger ? and also the .exe file is coded in VBA.

Thanks

Divy

Re: Calling an external program using a Trigger

Posted: Mon Apr 02, 2012 1:20 pm
by amosbatto
divyladha wrote:Can a .exe file stored on the server be called using a PM trigger ? and also the .exe file is coded in VBA.
If the file is stored on the processMaker server, you can use exec() or passthru() in a Trigger to execute your .exe program. The tricky part is if you need to get output from the program. If the output is text and one line:
Code: Select all
$output = exec("C:\MyDirectory\MyProgram.exe");
If more than one line:
Code: Select all
$output = "";
exec("C:\MyDirectory\MyProgram.exe", $output);
$line1 = $output[1];
$line2 = $output[2];
Best to debug it this way:
Code: Select all
$output = "";
exec("C:\MyDirectory\MyProgram.exe", $output);
var_dump($output);
die;
Also not the bug about Windows paths if using PP before version 5.3.0:
alvaro at demogracia dot com 27-Dec-2010 05:27
In Windows, exec() issues an internal call to "cmd /c your_command". This implies that your command must follow the rules imposed by cmd.exe which includes an extra set of quotes around the full command:

- http://ss64.com/nt/cmd.html

Current PHP versions take this into account and add the quotes automatically, but old versions didn't.

Apparently, the change was made in PHP/5.3.0 yet not backported to 5.2.x because it's a backwards incompatible change. To sum up:

- In PHP/5.2 and older you have to surround the full command plus arguments in double quotes
- In PHP/5.3 and greater you don't have to (if you do, your script will break)

If you are interested in the internals, this is the source code:

sprintf(cmd, "%s /c \"%s\"", TWG(comspec), command);

It can be found at http://svn.php.net/viewvc/ (please find php/php-src/trunk/TSRM/tsrm_win32.c, the comment system doesn't allow the direct link).

Calling an external program using a Trigger

Posted: Wed Nov 19, 2014 9:42 am
by SwondeR
I'd like to be able to trigger my predefined lighting and media scenarios with external scripts

I've read a bit about /usr/pluto/bin/MessageSend

but I'm not sure if that is what I am looking for or if that can only be used to update status rather than make the events happen

can anyone offer me any advice on how this is best accomplished?

Re: Calling an external program using a Trigger

Posted: Sun Sep 27, 2015 12:12 pm
by np97190
Can anybody share some examples of script task and how to call a external script with passing arguments.

Re: Calling an external program using a Trigger

Posted: Mon Sep 28, 2015 5:37 am
by np97190
$retval=exec("/usr/bin/whoami");
this piece of code returns apache. how can i set the user as root to execute the code.

thanks

Re: Calling an external program using a Trigger

Posted: Wed Nov 04, 2015 11:17 pm
by ethanpresberg
You would need to either execute the command as sudo or login via su root and execute the command.

You would need to typically put in the root password, so it would probably be easier to write a shell script that does this and simply call it in the manner that you are doing it.

Re: Calling an external program using a Trigger

Posted: Wed Jan 04, 2017 4:45 am
by RichardBracken
The suspect that your problem is the [-1] part because you are using a referencer to a file, but that referencer doesn't exist in this context. You need to use a real filename, not a reference. Also, you need to have a second parameter to capture what is returned by the function.