hiteksoftware.com Forum Index hiteksoftware.com
User discussion forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Run command on multiple files - Array help

 
Post new topic   Reply to topic    hiteksoftware.com Forum Index -> Frequently Asked Questions
View previous topic :: View next topic  
Author Message
Navigate



Joined: 07 Jun 2010
Posts: 6

PostPosted: Thu Jun 10, 2010 10:41 am    Post subject: Run command on multiple files - Array help Reply with quote

Directory will have an unspecified number of files.
I want to run a windows command on each of the files.
Specifically, "lpr.exe -S 10.10.10.10 -P PCL <filename>"
Where <filename> is the full path to each of the files in the directory.

I have a "Directory Listing" task to put the file list in an array.
How do I loop through the array and launch a "Windows Command" task with the filename as a command line parameter?

Or am I approaching this wrong all together.

Automize Enterprise 9.01

Thanks!
Back to top
View user's profile Send private message
melvin
Site Admin


Joined: 25 May 2006
Posts: 635
Location: Santa Barbara, california

PostPosted: Thu Jun 10, 2010 11:07 am    Post subject: Reply with quote

Dirlist + array loop tasks will work like you described. You would have to use the variable from the array loop task.
if your array loop task title is arrayloop, the filename in each loop would be:
arrayloop::CurrentRow-Column1
so, your commandline would be:
lpr.exe -S 10.10.10.10 -P PCL $%arrayloop::CurrentRow-Column1%$

The simpler way (1 task) would be to use a directory loop task (task title = dirloop). For every filename, run the windows command task and commandline would be:
lpr.exe -S 10.10.10.10 -P PCL $%dirloop::CurrentFilename%$
Back to top
View user's profile Send private message Send e-mail
Navigate



Joined: 07 Jun 2010
Posts: 6

PostPosted: Thu Jun 10, 2010 1:19 pm    Post subject: Reply with quote

Thanks Melvin!
I now understand how to use the variables.

I used your suggestion of a single task directory loop.
It works great if I use notepad.exe $%dirloop::CurrentFilename%$
It does not work if I use lpr.exe or c:\windows\system32\lpr.exe
Yet, I can go to the command prompt and run the command manually without issue.
I am not sure how to troubleshoot this issue. I don't see anything in the output or error logs to explain why lpr.exe is not running.

Any ideas?
Back to top
View user's profile Send private message
melvin
Site Admin


Joined: 25 May 2006
Posts: 635
Location: Santa Barbara, california

PostPosted: Fri Jun 11, 2010 3:30 pm    Post subject: Reply with quote

what is the working directory entered? I would use:
c:\windows\system32

since that is where lpr.exe is located.
Back to top
View user's profile Send private message Send e-mail
Navigate



Joined: 07 Jun 2010
Posts: 6

PostPosted: Mon Jun 14, 2010 7:13 am    Post subject: Reply with quote

Set the working directory to c:\windows\system32; no help.

I read that using 'command' instead of 'windows command' task offers a little better logging information, so I changed my task to use command and found the error below. The lpr.exe is in this directory and I can run it fine from a command prompt. It does not matter if I use the NT Service module or not, I get the same error. OS is Windows 2008 SP2 and UAC is disabled. There is no anti-virus or other software running that would interfere. My account has permission to execute lpr.exe and does so without issue from the command line.

When specifying the command line for the command task, I tried browsing to lpr.exe and do not see it. I checked the attributes of this file (attrib lpr.exe) and it is not hidden.

What am I missing?

Error:
Java.io.IOException: Cannot run program "c:\windows\system32\lpr.exe" (in directory "c:\windows\system32"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at com.hitek.engine.mods.script.CommandTask.commandTask(CommandTask.java:86)
at com.hitek.engine.mods.script.CommandTask.run(CommandTask.java:44)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
Back to top
View user's profile Send private message
melvin
Site Admin


Joined: 25 May 2006
Posts: 635
Location: Santa Barbara, california

PostPosted: Wed Jun 16, 2010 4:32 am    Post subject: Reply with quote

if you are sure the .exe is there in system32, check for case sensitivity in path/filename.
Back to top
View user's profile Send private message Send e-mail
Navigate



Joined: 07 Jun 2010
Posts: 6

PostPosted: Wed Jun 16, 2010 4:44 am    Post subject: Reply with quote

Case sensitivity did not help.
I am quite sure that lpr.exe is in system32
Hard to believe, I know. Here is a copy of some command line functions so you can see for yourself that it does exist and I have access to run the .exe

C:\Windows\System32>dir lpr.exe
Directory of C:\Windows\System32

01/19/2008 08:51 AM 10,752 lpr.exe
1 File(s) 10,752 bytes
0 Dir(s) 114,947,280,896 bytes free

C:\Windows\System32>attrib lpr.exe
A C:\Windows\System32\lpr.exe

C:\Windows\System32>lpr /?
Sends a print job to a network printer
Usage: lpr -S server -P printer [-C class] [-J job] [-o option] [-x] [-d] filename

Options:
-S server Name or ipaddress of the host providing lpd service
-P printer Name of the print queue
-C class Job classification for use on the burst page
-J job Job name to print on the burst page
-o option Indicates type of the file (by default assumes a text file)
Use &quot;-o l&quot; for binary (e.g. postscript) files
-x Compatibility with SunOS 4.1.x and prior
-d Send data file first
Back to top
View user's profile Send private message
melvin
Site Admin


Joined: 25 May 2006
Posts: 635
Location: Santa Barbara, california

PostPosted: Wed Jun 16, 2010 10:15 pm    Post subject: Reply with quote

when using service, lpr will not work.
But it seems like lpr should work through Automize when the engine is NOT run as a service. not sure what the problem could be.
Back to top
View user's profile Send private message Send e-mail
Navigate



Joined: 07 Jun 2010
Posts: 6

PostPosted: Wed Jun 23, 2010 10:34 am    Post subject: Reply with quote

I tried 2 more things before giving up:
1. Remove lpr feature and re-added it in Win2008
2. Call batch file from Automize, batch file to run lpr (got same errors)
Note: I could run the batch file outside of Automize no problem

I finally moved the whole thing to WinXP and have had no issue calling lpr, including from Automize service.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    hiteksoftware.com Forum Index -> Frequently Asked Questions All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group