WatchDirectory Forum
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl
watchDirectory forums >> Plugins >> Multi-step process
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl?num=1405713124

Message started by David Hostetter on Jul 18th, 2014 at 9:52pm

Title: Multi-step process
Post by David Hostetter on Jul 18th, 2014 at 9:52pm
Hi, I am trying to create task(s) for the following:

Step 1: Encrypt a file
Step 2: Upload the encrypted file
Step 3: Rename the original file to indicate it has been encrypted and sent.

I am trying to do this in only two tasks = windows services.

First step is easy.  I have a task to detect the new file and run a batch file that encrypts it.  Encryption routine adds an additional extension to the target.

Second step is easy.  I have a task to detect the encrypted file extension and upload it.  The upload task also renames the encrypted file to *.sent.  I do not require to keep the uploaded file, I only rename it as a potential trigger for the next step.  If I could avoid this and simply delete the file after upload I would prefer that.

For the third step I am running into a challenge.

I could have a third task to detect the .sent files and then call a batch to rename the original file and delete the .sent.  And if I cannot find a better solution this is what I might do.

But I would prefer not to have three windows services to accomplish this.  At that point it seems better just to write my own script and run that as a single windows service.

I tried to do this by combining Step 2 and 3 into a sub-task task that triggers off of the encrypted file creation.  The first sub task does the upload, the next sub task ... can't run a batch file?  :-?  Or be based on an existing task that runs a batch file?  Or in some other way rename the original file which is not the current target?

A sub-task can run an executable so maybe I run the command shell as the executable and pass as a parameter the batch file to handle the renaming?  In that case I sure hope I can somehow pass the target file as a parameter.

Thoughts?  Ideas?

Thanks for a really nice system tool.  I am finding it quite useful.

Title: Re: Multi-step process
Post by David Hostetter on Jul 18th, 2014 at 10:49pm
I tried "start any program" as a sub-task and I think I have discovered that you cannot pass arbitrary parameters to the program, only WD's environment variables.  So I cannot call "cmd.exe" and pass "/k c:\my_dir\my_batch.bat" "%WD_File%"

What happens is cmd.exe opens but no command is executed within.  :(

It was worth a try...

Title: Re: Multi-step process
Post by Gert on Jul 20th, 2014 at 8:16am
Hello David,

Cant you just use the %WD_FILE% variable inside your script?

Title: Re: Multi-step process
Post by David Hostetter on Jul 20th, 2014 at 9:48pm
Yes, I probably can.  Assuming that when I run cmd.exe as the executable program the environment variables are created in that environment.  But I can't get cmd.exe to start a batch file as a parameter.  That's the problem.

I don't suppose there is some secret way to make a sub-task run a batch file?

Title: Re: Multi-step process
Post by Gert on Jul 21st, 2014 at 7:51am
I just tried and it works fine for me, see attached. All WD_ variables ( www.watchdirectory.net/wdhelp/plugins/wdopAutoRunBatEnv.html ) are available in your script.

I used the /C switch so the cmd window automatically closes when it is done.

Perhaps the cmd gets confused by your use of "quotes"??
21-7-2014_7-40-00.png (17 KB | 213 )

Title: Re: Multi-step process
Post by David Hostetter on Jul 22nd, 2014 at 3:51pm
Confirmed working.  Actually it's not the quotes.  My actual batch file has extension .cmd   That doesn't seem to work.  Renamed it to .bat and it works fine.  And you are also correct that the environment variables are available in the command environment - no need for me to pass them as parameters.

Thanks for looking at this.  I'm pleased this works like I hoped.

Title: Re: Multi-step process
Post by Verne on Jul 28th, 2014 at 9:34pm
I have been doing it like Gert described above and we have also successfully tested with pointing it directly to the batch file as well without using cmd.exe.

WatchDirectory Forum » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2017. All Rights Reserved.