Page 1 of 2

executecommand() with batch files

Posted: Wed Mar 09, 2011 12:41 am
by Cam
Hello,

We developed a TI process to trigger a .bat that copies files from one network path to the TM1 Server. It always displays a succesful msg box, but it never do anything, we suspect is a permissions problem, but we are not sure, because we can execute the file and it works.

Is there a way to see what's happening, why the process never executes. (debug option on tm1server.log can work?)

We tried cmd /c option, pointing to the location (D:\etc), executing with a user, executing with a chore, etc. Maybe we are not understanding how this function works and what permit we need to grant (documentation is little for this "powerful" TI function).

Any help will be good..

Thanks

Cam

Re: executecommand() with batch files

Posted: Wed Mar 09, 2011 1:59 am
by tomok
Remove the /c option and re-run the process. This should leave the box open and you will be able to see whatever message the system returned. You will probably have to login to the desktop of the TM1 server with the TM1 service account ID in order to see the command window though.dialog box

Re: executecommand() with batch files

Posted: Wed Mar 09, 2011 9:12 am
by dubs
put a pause in the batch file to keep the dos window open and see if you get any errors coming up

Re: executecommand() with batch files

Posted: Wed Mar 09, 2011 12:46 pm
by qml
... or put " > C:\myfile.txt" at the end of your command to print anything the OS says to a text file.

Re: executecommand() with batch files

Posted: Wed Mar 09, 2011 3:29 pm
by Cam
The problem is that we dont see the command window.. is so fast in messaging "successful".. (permits issue??)

We tried this on the server and on clients.

Re: executecommand() with batch files

Posted: Wed Mar 09, 2011 3:50 pm
by ajain86
from my experience, executecommand(), does not return anything back to TM1 (except that it had completed) and therefore TM1 always says a message successful.

My thinking was that the function just executed the .bat file and did not have any connection to it. The only thing it can do is wait for the script to finish to return back to TM1.

Are you able to just run the script directly without using TM1?
Also, I would second both options of putting a pause and/or exporting the command text to a file.

Are you giving the proper path for the script in TM1. You will need to give the full path it the script is outside the TM1 Data directory.

Re: executecommand() with batch files

Posted: Wed Mar 09, 2011 3:54 pm
by tomok
Cam wrote:The problem is that we dont see the command window..
Did you not even bother to read any of the suggestions????? Every one of them is giving you directions on how you can either keep the command window open, or capture the command window results to a text file, SO THAT YOU CAN SEE THE RESULTS!!! It doesn''t matter how fast the TI process if you follow one of these suggestions.

Re: executecommand() with batch files

Posted: Wed Mar 09, 2011 4:08 pm
by Steve Vincent
Cam wrote:The problem is that we dont see the command window.. is so fast in messaging "successful".. (permits issue??)

We tried this on the server and on clients.
Where you try it from is irrelevant, it will always do the same thing.

Anything you ask a TM1 service to do outside of TM1 itself will run using the same account permissions that the service is running under. You have to think like that account to be able to figure out what it is doing.

Imagine you have a local windows account called "TM1service" and all your TM1 models run as a service using this accounts' credentials. If you ask TM1 to run a bat file using a file path D:\windows then the TM1service account must have D: mapped and be granted the required permissions. Windows being the 1st class pain in the rear that it is will make that harder and more complicated when you start refering to data on other machines within the network. The main rule is to always use the UNC path and not local drive names. That removes one possible area for issues, the other is that Windows security policies insist that the account making the request for data on another server must also exist on that other server. Not only that, each local account must also have the same password. If not, they won't authenticate and the bat will probably output a file not found type of error.

Log in locally to the windows server as the account that runs your TM1 services. Then add the pause to the bat as suggested and run it. You should then see the errors TM1 is seeing and it should help you track down the problem.

Re: executecommand() with batch files

Posted: Wed Mar 09, 2011 9:16 pm
by Cam
Hello,

Sorry tomok, i did try that, we are analyzing all the answers, is interesting what Steve wrote, i try to do my best to understand :roll: which is expert advice like all of you.

On the Reference Guide
------------
ExecuteCommand
This is a TM1 TurboIntegrator function, valid only in TurboIntegrator processes.

This function executes a command line during a process. You can use ExecuteCommand to run a desktop application, but not a service
------------
this means tm1 cant executecommand() to open services, or not works when TM1 is runt as a service? We are running TM1 as a service.

Thanks,

Re: executecommand() with batch files

Posted: Thu Mar 10, 2011 9:58 am
by dubs
Cam I think what you need to do is forget about TM1 until the batch files works when executing manually outside of TM1, once you are confident it works then try executing it from TM1, otherwise it can be too hard to see what is going on, if it works outside tm1 but not inside tm1 it immediately narrows the possibilities of what is going wrong (and I would check permissions first)

Re: executecommand() with batch files

Posted: Thu Mar 10, 2011 3:48 pm
by wissew
dubs wrote:Cam I think what you need to do is forget about TM1 until the batch files works when executing manually outside of TM1, once you are confident it works then try executing it from TM1, otherwise it can be too hard to see what is going on, if it works outside tm1 but not inside tm1 it immediately narrows the possibilities of what is going wrong (and I would check permissions first)

dubs has got you going in the right direction. Remember the tm1 server account needs to be logged on to the desktop and the drives involved should be mapped by the account. If it works when you execute it off the server desktop logged in under the TM1 service account it should work from TI. The only problems I have had is when there are conflicting bat file running on the server (ie a back job).

Re: executecommand() with batch files

Posted: Mon May 09, 2011 3:36 pm
by Cam
A little late, but we solved it, mainly permissions issues on my TM1 Service account (access to log on the server). Now copying files from different servers works quite well. This function is pretty useful, we prefered to use variables instead of batch files so we can add parameters.

Thanks for the help!

Re: executecommand() with batch files

Posted: Mon Jan 07, 2013 12:42 pm
by l_kothamasu
Hi Cam,
If you don't mine, could you please let me know how you solved this issue? Currently, I am also facing similar kind of issue, which means batch files are working manually, but when I used EXECUTECOMMAND() in TM1 to fetch the batch files then it's not working and message populates as "TM1 executes successfully". I have many ways, but still not working.
Thanks in advance.

Re: executecommand() with batch files

Posted: Mon Jan 07, 2013 1:44 pm
by qml
Have you tried any of the methods suggested in this thread to find out what message the OS is returning? There are a few possible reasons for this problem and yours isn't necessarily the same as Cam's.

Re: executecommand() with batch files

Posted: Mon Jan 07, 2013 2:57 pm
by whitej_d
Hi,

You need to make sure the TM1 service account has the relevant permissions to the location on the network. Then you need to restart the TM1 service to apply any new windows security rights to the service.

For some reason any new rights granted to a windows user only take effect when the service is restarted. You'll find it works manually when logged on as the user (after logging off and on again once the security rights have been granted), but not via TI until the service has been restarted.

Re: executecommand() with batch files

Posted: Mon Jan 07, 2013 3:24 pm
by l_kothamasu
Hi,

Thanks for your reply (white and QML)

- When I execute batch files manually (which means just double click the batch files) then I am receiving emails (One for successful and another for Unsuccessful) to my account.
- When I had written the below coding in Prolog tab (5 different ways) then I am not receiving any email to my account. Here I am planning to write the coding as If condition to satisfy only one batch files (successful or unsuccessful). Please see below coding:
WAY 1:
-------
§ No Data source
§ No Variable declaration
§ In Epilog Tab
vResult = 0;
set = EXECUTEPROCESS('Process_Name');
IF (set = ProcessExitNormal());
vResult = 1;
ENDIF;
IF(vResult = 1);
# If it success
vCommandLine = 'E:\path of success.bat';
ELSE;
# If it failed
vCommandLine = 'E:path of failure.bat';
ENDIF;
ExecuteCommand(vCommandLine, 0);

WAY 2:
-----------------
§ No Data source
§ No Variable declaration
§ In Epilog Tab
return_Value = ExecuteProcess('Process_Name');
IF(return_Value = ProcessExitSeriousError() );
#If it failed
vCommandLine = 'E:path of failure.bat';
ELSE;
# If it failed
vCommandLine = 'E:path of success.bat';
ENDIF;
ExecuteCommand(vCommandLine, 0);

Way 3:
----------------
vResult = 0;
set = EXECUTEPROCESS('process 1');
IF (set = ProcessExitNormal());
vResult = 0;
ENDIF;
IF(vResult <> 0);
# SUCCESS
vSuccess = 'E:path of success.bat';
ExecuteCommand(vSuccess,0);
ELSE;
# FAILED
vFailure = 'E:path of failure.bat';
ExecuteCommand(vFailure,0);
ENDIF;

Way 4:
----------------
vResult=0;
pcube = 'cube_Name';
set1 = EXECUTEPROCESS('Process_NameOne');
CELLPUTS(TIMST(NOW, '\Y \M \d \h:\i:\s'), pcube,'process_NameOne', 'Time');
IF(set1=ProcessExitNormal());
CELLPUTN(1,pcube,'process_NameOne','Count');
ENDIF;
set2 = EXECUTEPROCESS('Process_NameTwo');
CELLPUTS(TIMST(NOW, '\Y \M \d \h:\i:\s'), pcube, 'process_NameTwo', 'Time');
IF(set2=ProcessExitNormal());
CELLPUTN(1,pcube,'process_NameTwo','Count');
ENDIF;
IF(CELLGETN('cube_name','All','Count')=2);
vResult=1;
ENDIF;
IF(vResult =1);
# If it success
vCommandLine = 'E:path of success.bat';
ELSE;
# If it Failed
vCommandLine = 'E:path of failure.bat';
ENDIF;
ExecuteCommand(vCommandLine,0);

Way 5:
-------------------------------
- In prolog tab or Epilog tab (Tried on both tabs)
Executecommand(‘E:path of successful.bat’, 0);

Note: All coding is working and getting message as "Process Executed successfully", but I am not receiving any email. I am Testing this coding in TM1 Development server as a Admin user access. So, I think it would be a permission issue or security issue, If it is a any of the these causes, can some one please update what kind of security should i need to double check.

Thanks in advance.

Re: executecommand() with batch files

Posted: Mon Jan 07, 2013 4:12 pm
by whitej_d
Hi,

Go through these exact steps:

1. Check your windows services (on the server) to see what username TM1 is running under. If it's local system, then change it to a named user.
2. Log into the server as the user which is running TM1.
3. Try running your batch file manually while logged in as the TM1 Service user. If it doesn't work as expected, then change the security settings for the TM1 service user to allow you to run it successfully. It will probably need execute rights to the folder where the bat file is stored, but also read/write rights as appropriate for any file copy/move that takes place in the bat.

4. Log out and log back in to Windows as the TM1 service user to apply the new security rights. Check you can manually execute the batch file.
5. Restart the TM1 service.

Now you should be able to successfully run the batch process from the TI.

Re: executecommand() with batch files

Posted: Tue Jan 08, 2013 3:22 am
by l_kothamasu
Hi White,

I tried as per below instructions, but still I am not able to receive any email if run TI process (I tested by restarting the server and I checked the TM1 users access (It is Admin user to execute TI process). Is there any other way to rectifify this issue?

Thanks in advance.

Regards,

Re: executecommand() with batch files

Posted: Tue Jan 08, 2013 5:02 am
by rmackenzie
l_kothamasu wrote:I checked the TM1 users access (It is Admin user to execute TI process).
The advice is to check the the name of the account that the TM1 service is running under. If this isn't your account then there may be a permissions issue where by you can run a batch file to send an e-mail, but the account running the TM1 service cannot. It's not anything to do with whether a user is an Admin within TM1. Some common accounts used to run services have different permissions which is why whitej_d is advising you to change the service account to your own in order to propertly test the batch files.

To check the account that the TM1 service is running under you need to goto the Services console (run services.msc from Start->Run) on the server where TM1 is running. Find the service, right-click and somewhere in the Properties option it will tell you what account.

If you don't have access to the TM1 server then you might have to ask someone in your IT department to help you with this.

Re: executecommand() with batch files

Posted: Tue Jan 08, 2013 5:48 am
by yyi
vCommandLine = 'E:\path of success.bat';
also noticed that your command line doesn't have "cmd /c " before the "E:\*.bat"
i found on my instance, it needs the prefix before the path & bat file name