Execute task and system environment variables - VisualCron - Forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


osirisja
13 years ago
Hi Support

Okay now I have come across an issue that has really stumped me! I'm hoping you can help?

I have two servers. A workflow is initiated from server 1. The final task on server 1 writes a Control file to a Trigger folder on Server 2. This initiates an external application (execute) that exists on server 2. The command line of the Execute task is 'C:\myapp\exefolder\myapp.exe'.

Now, the application 'myapp.exe' requires access to system environment variables on server 2 (everything runs on on Windows 2008 R2 server running under VMWare ESX). The system environment variables point to a software Licensing Server so it is critical for the exe to access them otherwise the application won't run. However, they cannot be accessed.

I have tried every variation of Foreground/Background execution, Shell execute, Working directory, and Credentials, but I cannot get the environment variables picked up no matter what I try. I have also tried defining the environment variables as User env vars, but it makes no difference.

Now here is the strange thing - If I write the exact same executable command line in to a DOS Batch File, and execute that with the 'Execute' task, it works perfectly.

Have I overlooked something obvious here?

Cheers

Andy

Sponsor
Forum information
osirisja
13 years ago
Hi Support

Any feedback on this issue?

Cheers

Andy
Support
13 years ago
Just to verify:

  • the exe is running on server 2
  • you are trying to access an environment variable on server 2 from the exe
  • are you have a problem reading the variable on server 2 or passing he variable. For example, if you set you exe to write the value to a file, does that work - or is it impossible to read values at all from your exe. If so, which language and code do you use for reading the variable.

Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
osirisja
13 years ago
Hi Henrik

Yes, the Exe is running on Server 2, and the 'Execute Task' is defined on Server 2.

Yes, the System Environment Variable is defined on Server 2 from the Exe running on Server 2

Correct, on Server 2 the EXE doesn't recognise environment variables if it is triggered from Server 1. The VC Task 'Execute' is defined on Server 2. The Exe is a third party executeable and it uses the OEM codepage (which is 850) (if that's what you mean?). The VC Execute Task itself is using Windows-1252 encoding.

What is REALLY strange is that this executable is triggered by a simple Trigger file written from Server 1, so Server 1 writes a trigger file to server 2, which invokes the Execute Task. This runs the EXE but it fails because it can't read the environment variables. However, if I manually run the Execute Task on Server 2 (right click/execute task), it works fine!

So it seems to be something to do with the trigger file?

Incidentally - this is only a problem with the EXECUTE task - if I replace it with a DOS BATCH file which calls the executable, it works fine. Also the same if I call the exe with a Powershell script.....

Cheers

Andy
Support
13 years ago
What if you change from "API" to "Managed" in the Execute settings?
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
osirisja
13 years ago
Hi Henrik

I've tried both Managed and API, and Network credentials and Profile, and even with no credentials - all give the same result.

Also, in the task itself, it is not updating any of the task columns - no matter if I trigger it with a file or if I manually run it.

UPDATE : Out of frustration I've just deleted the whole job and redefined it from scratch - guess what - it all works! When I think back I had 'cloned' the original execute task - I wonder if this caused some issues with it?

I will watch for this happening again Henrik - thanks for your help

Cheers

Andy
Support
13 years ago
This environment Variable - was it written to the standard output?
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
osirisja
13 years ago
Yes and No, when the exe runs, if I specify Foreground Execution and Run in Shell, it displays the command dialogue and I can see the messages appear in there if I'm quick enough!

The application itself is a bit strange because it writes some messages (normal process messages) to STDOUT, whereas System messages it writes to STDERR, and in here if the application runs successfully, I can see the results of the environment variables being applied - for example, Product Authorised messages. What is trange is that even though there is output being written to STDERR, the Task/Job completes successfully.

Cheers

Andy

Support
13 years ago
No output can be captured when using "Use shell execute". Maybe that is the problem.

Writing to the standard error is just a design error from the application. An application does not fail because standard error is added - only when exit code is not zero.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
osirisja
13 years ago
Hi Henrik

I raised this issue some weeks back about not being able to read environment variables when running an Executable Task. I have just tried setting up a similar task as before and again it can't read the system environment variables. I am running VC on a single instance of Windows 7 x64 and the executable is running locally as well.

the task execution context is Background and i'm not running as Shell Execute or in hidden window, although I have tried all of them.

I haven't set any task credentials as I am logged on locally as admin. I have also created the environment variables as USER env's as well as SYSTEM. Is there something else I need to do to enable VC and the Executable to read and understand system environment variables?

Cheers

Andy
Support
13 years ago
I did a test to verify this on Windows 7 x64.

I created a script, a batch file with this line:

SET myname=Henrik

I created another script:

@echo off
echo %myname%

I created two Execute Tasks, one with the set and one with the get.

Now, getting and setting user variables will only work if "With profile" is set and running with a Credential.

I first set and then get and got my name as output in the "get" Task.

I noticed that this only works when using API mode.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
osirisja
13 years ago
hi Henrik

I have also found that when you use set variables in batch, cmd or script files there is not a problem. I can call my executable issuing the relevant Set commands first and it works fine, as this is a local and temporary command shell session. However I need to call the executable directly and pass a long string of VC user variables as arguments.

I will try the With Profile setting and API mode, but I have tried these settings already with no luck.

I'm not sure even if there is a way to dynamically set environment variables at the same time as running an executable?

cheers

Andy
Support
13 years ago
Originally Posted by: osirisja 

I'm not sure even if there is a way to dynamically set environment variables at the same time as running an executable?



Not yet. We are planning to add separate Tasks for this (Get/Set)
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
osirisja
13 years ago
Hi Henrik

Okay - I will watch out for that update. Meanwhile I will need to come up with a suitable way of achieving this.

Thanks

Andy
Scroll to Top