Solved

Explain how this works

Posted on 2014-01-07
4
296 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 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
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…

730 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