?
Solved

Explain how this works

Posted on 2014-01-07
4
Medium Priority
?
300 Views
Last Modified: 2014-01-08
Someone gave me this recursive code, but it would fail with this error message:
"Program 'JPEGtoPDF.exe' failed to run: Not enough quota is available to process this command"
I Googled and it seemed to say I was out of resources, but I am not even close, so I decided to watch the program work. I figured out "gci" stood for Get-ChildItem and I started off inserting a SLEEP(1) after the jpegtopdf.exe line. This was painfully slow and only one filename was processed between sleep(1).
I then used the FOR loops to slow it down, but to my surprise it allowed jpegtopdf.exe to process the entire directory it was in and then pausing a moment before doing the next directory\subfolder.
I figure this has something to do with SLEEP(1) stopping the whole program, while the FOR loops allow the executable to run to a certain point and then spit out the results?
What do you think?
Also, is there a web page that can explain how this program works so that I can learn how to do this on my own? I see the %{ after the pipe a lot and then the $(${_.objectname, but I don't know how it works or where to start looking. I Googled, but did not find anything for beginners.
thanks!


$search = "C:\photos"
Get-ChildItem $search -filter *.jpg -Recurse | %{
    write-host "Begin work on :" $_.FullName
    jpegtopdf.exe "$($_.DirectoryName)\$($_.BaseName).PDF" $_.FullName
    #slow it down with FOR loops works.
    #SLEEP(1) pauses for each filename
    for($i=0;$i -lt 1000;$i++)
    {
    for($o=0;$o -lt 100;$o++){}
    }
 }
0
Comment
Question by:johnj_01201
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39763095
Conversion programs tend to eat up the memory. Have you tried increasing the paging file?
0
 
LVL 1

Author Comment

by:johnj_01201
ID: 39763114
Yes, the issue turned out to be the Remote Powershell Window. The program runs fine, 1 file at a time and without the FOR loops, when run on the local server.
I found 1 comment in Google that told there's a limit on Windows Messages and if you fill it up it trips a wire causing this error so that it does not overflow.
0
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 39763429
| % is shortcut for foreach. $_ is self

Your script translates to:
$search = "C:\photos"
$results = Get-ChildItem $search -filter *.jpg -Recurse
foreach ($result in $results) {
     write-host "Begin work on :" + $result.FullName
    jpegtopdf.exe $result.DirectoryName + "\" + $result.BaseName + ".PDF" $result.FullName
}

Open in new window


HTH,
Dan
0
 
LVL 1

Author Closing Comment

by:johnj_01201
ID: 39765035
THANK YOU!!!
0

Featured Post

Ransomware Attacks Keeping You Up at Night?

Will your organization be ransomware's next victim?  The good news is that these attacks are predicable and therefore preventable. Learn more about how you can  stop a ransomware attacks before encryption takes place with our Ransomware Prevention Kit!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question