Solved

Explain how this works

Posted on 2014-01-07
4
291 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
  • 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 34

Accepted Solution

by:
Dan Craciun earned 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
A procedure for exporting installed hotfix details of remote computers using powershell
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now