Need some help to create a render-distribution-script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
ILM
Posts: 10
Joined: 11 Jan 2016 02:43

Need some help to create a render-distribution-script

#1 Post by ILM » 11 Jan 2016 02:59

Hi there,

first of all two infos.
1) About me: I now the most important dos commands and can handle batch files. I have already some data-backup batches by myself, but this one is too tricky for me. That is why I need your help.
2) About this script: I have a server (LAN not WAN) that has a folder with at least 1000 files. Those files are ray tracing files that should be rendered by other render-pcs in the LAN. I want to write a script, that searches for a file from the server. copies it to another folder and then renders it.

This is what exactly the script should do:

Code: Select all

if pvengin64.exe is running then do nothing ||checks if the pc is already rendering. if he does it should not start a new render.
else:
   get the filename of the first (or any) file from "\\server\all files"
   move that file from "\\server\all files" to "\\server\rendered files"
   start c:\pvengine64.exe with the following paramters "/exit /render \\server\renderes files\filename" || the /exit command tells the programm to close after it has finished rendering


Bonus: I thought about starting the batch every 4 Minutes via windows task scheduler. The other option is to start it manually. But then there has to be included a loop in the batch itself.

Thank you very very much for your help!

ILM
Posts: 10
Joined: 11 Jan 2016 02:43

Re: Need some help to create a render-distribution-script

#2 Post by ILM » 11 Jan 2016 10:10

This is what i got until now:

Code: Select all

:start
tasklist /FI "IMAGENAME eq pvengine64.exe" | findstr "pvengine64.exe" >nul
if %ERRORLEVEL% == 1 goto render
timeout /t 240
goto start

:render
   |MISSING PART (move file and start the renderprocess)
:eof
exit

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need some help to create a render-distribution-script

#3 Post by foxidrive » 11 Jan 2016 16:24

You mentioned you want to search the server on the LAN and render locally.

Does the server require authentication? Is the file being moved from the server to the local machine?
What happens to the files when they are done?

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Need some help to create a render-distribution-script

#4 Post by ShadowThief » 11 Jan 2016 16:55

You may need to use the net use command to temporarily mount the server locations as network drives, but from there the move command will work like usual.

ILM
Posts: 10
Joined: 11 Jan 2016 02:43

Re: Need some help to create a render-distribution-script

#5 Post by ILM » 11 Jan 2016 16:58

well ok, I do not need to "search" for the server. I can provide the IP address.

The Lan Server does not need any authentification. The folder is shared to everyone in the network. (Its a LAN only used for rendering.)

the file must not be copied to the local machines. the local machine only has to start the pvengine64.exe locally and get the path\file as input parameters. but it must be copied to the second folder on the server so that the other machines do not start to render the same file.

nothing happens to the files after rendering. the file stays at the server and the render software places a *.png with the equal filename in the same folder.

ILM
Posts: 10
Joined: 11 Jan 2016 02:43

Re: Need some help to create a render-distribution-script

#6 Post by ILM » 11 Jan 2016 17:00

ShadowThief wrote:You may need to use the net use command to temporarily mount the server locations as network drives, but from there the move command will work like usual.


yeah I used that command once for another project. my biggest problem right now is
a) how to copy only 1 file of the directory
b) save the filename of that file to a variable
c) start the renderer with the new path and the variable filename as parameter

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Need some help to create a render-distribution-script

#7 Post by ShadowThief » 11 Jan 2016 18:35

Depends on how the files in \\server\all files are sorted. I assume it's sorted alphabetically by name, so you could say

Code: Select all

::This assumes that X: and Y: are not already in use
net use X: "\\server\all files"
net use Y: "\\server\rendered files"

:: This will ignore any folders in the source directory
for /f "delims=" %%A in ('dir x:\ /b /a:-d /o:-n') do set first_file=%%A

move "X:\%first_file%" "Y:\%first_file%"

start "" C:\pvengine64.exe /exit /render "Y:\%first_file%"


or something like that. You will probably have to tweak it to make it work; I don't have any network drives I can mount to test this.
Last edited by ShadowThief on 12 Jan 2016 08:14, edited 1 time in total.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Need some help to create a render-distribution-script

#8 Post by Squashman » 11 Jan 2016 20:11

I am not understanding how any of the other computers would know not to render the file. What happens if they both try to render the same file at the same time?

ILM
Posts: 10
Joined: 11 Jan 2016 02:43

Re: Need some help to create a render-distribution-script

#9 Post by ILM » 12 Jan 2016 02:10

@ShadowThief: Thank you very much, I will try that tomorrow.

Squashman wrote:I am not understanding how any of the other computers would know not to render the file. What happens if they both try to render the same file at the same time?

That is why I want to move the file first from "all files" to rendered files. i move it and start the render process after moving. as every pc is looking for a new file to move and render in the "all files" directory it will not be able to take the same file.

the only problem that might occure is that two pcs try to move the same file. but to let this happen, they would have to finish the last render process in the exact same second and look for the next file to render at the same time. i think that is almost impossible to happen.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need some help to create a render-distribution-script

#10 Post by foxidrive » 12 Jan 2016 04:18

ILM wrote:I want to write a script, that searches for a file from the server. copies it to another folder and then renders it.

move that file from "\\server\all files" to "\\server\rendered files"


You can see where the confusion arises.

ILM
Posts: 10
Joined: 11 Jan 2016 02:43

Re: Need some help to create a render-distribution-script

#11 Post by ILM » 12 Jan 2016 04:56

foxidrive wrote:
ILM wrote:I want to write a script, that searches for a file from the server. copies it to another folder and then renders it.

move that file from "\\server\all files" to "\\server\rendered files"


You can see where the confusion arises.


Oh I am sorry. I wasnt precise enough in the introduction (as an excuse: I am not a native speaker). so my pseudo code is what i am aiming for. the file should be moved.

I will try the suggestion above tomorrow. and leave you a feedback.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Need some help to create a render-distribution-script

#12 Post by Squashman » 12 Jan 2016 07:30

foxidrive wrote:
ILM wrote:I want to write a script, that searches for a file from the server. copies it to another folder and then renders it.

move that file from "\\server\all files" to "\\server\rendered files"


You can see where the confusion arises.

Exactly. Copy was said four times which was confusing the hell out of me!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need some help to create a render-distribution-script

#13 Post by foxidrive » 13 Jan 2016 05:18

You were kind enough to reply in a pleasant manner, and that's beginning to be very rare these days.

Here's a script that may work - it processes one file and then using GOTO it effectively exits the loop - there is a delay, as the loop still counts, but 1000 files should be almost instant.

If the rendering engine doesn't wait while a file is processed then the start command can be added.

Code: Select all

@echo off
:begin
tasklist /FI "IMAGENAME eq pvengine64.exe" | findstr /i "pvengine64.exe" >nul || (
for %%a in ("\\server\all files\*.*")  do (
   move "%%a" "\\server\rendered files"
   "c:\pvengine64.exe" /exit /render "\\server\rendered files\%%~nxa"
   goto :begin
))
timeout 240   
goto :begin

ILM
Posts: 10
Joined: 11 Jan 2016 02:43

Re: Need some help to create a render-distribution-script

#14 Post by ILM » 13 Jan 2016 05:54

Squashman wrote:
foxidrive wrote:
ILM wrote:I want to write a script, that searches for a file from the server. copies it to another folder and then renders it.

move that file from "\\server\all files" to "\\server\rendered files"


You can see where the confusion arises.

Exactly. Copy was said four times which was confusing the hell out of me!


I am really sorry! I hope i was able to solve your confusion.

For anyone who contributed to my problem: Thank you very much. Even I do not understand everything the final script works as intended.

If anyone is interesed this is the final script:

Code: Select all

net use X: "\\192.168.1.1\Povray Render Files\Video\files_not_rendered"
net use Y: "\\192.168.1.1\Povray Render Files\Video"

:start
tasklist /FI "IMAGENAME eq pvengine64.exe" | findstr "pvengine64.exe" >nul
if %ERRORLEVEL% == 1 goto render
timeout /t 10
goto start

:render
:: This will ignore any folders in the source directory
echo off
for /f "delims=" %%A in ('dir x:\ /b /a:-d /o:-n') do set first_file=%%A
echo on

move "X:\%first_file%" "Y:\files_rendered\%first_file%"

start "" "C:\Program Files\POV-Ray\v3.7\bin\pvengine64.exe" /exit /render "Y:\files_rendered\%first_file%"
goto start

exit


Thank you very much!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need some help to create a render-distribution-script

#15 Post by foxidrive » 13 Jan 2016 08:57

ILM wrote:For anyone who contributed to my problem:


I hope I didn't do that - I contributed to the solution. :D

Sorry, just poking fun there and I shouldn't as your mother tongue isn't English - but did you see my post just before yours?

Post Reply