I have a command line code as follows -
for /r %%v in (*.max) do start %%v
It opens any Max file in the same folder - great.
I want it to also tell max to run any number of scripts when the file has opened, there are guides on how to do this on the 3dsMax help for eg:
-U MAXScript = (this will open MAXScript and run a certain script on the end of a fresh 3dsmax command load.
However this does not work on the end of the initial code I need to use.
I have been researching how this could work for 2 days but keep going in circles.
Please help.
Adam
try for /r %%v in (*.max) do START cmd.exe /C %%v
You might want to take a look at using 3dsmaxbatch.exe instead of 3dsmax.exe
Here is a link to the 2019 documentation:
https://knowledge.autodesk.com/support/3ds-max/learn-explore/caas/CloudHelp/cloudhelp/2019/ENU/3DSMax-Batch/files/GUID-48A78515-C24B-4E46-AC5F-884FBCF40D59-htm.html
The command line to load a max file then execute a script should look like this
3dsmaxbatch.exe -sceneFile C:/some/path/to/maxfile.max C:/some/path/to/script.ms
Related
My Problem
As there are a ton of threads that address 'using a batch file to return file modify date' (or delete files older than, etc) - let me first specify my issue.
I'm looking to create a batch (not PowerShell, etc) that will return the last modify date of a specific file given UNC path and filename.
Code, Attempt 1
I've taken a peek at a few potential solutions on other threads, but I've run into a number of unique issues. The first and most obvious solution for this would be the "ForFiles" command in batch. For example:
set myPath=\\myUNCpath
set myFile=myFileName.csv
forfiles /p "%myPath%" /m %myFile% /c "GoTo OldFile" /d -6
Thus, if the file is older than I want -- jump to a specific section of my batch for that. However, this yields the error:
ERROR: UNC paths (\machine\share) are not supported.
However, this cmd won't work due to the use of UNC (which is critical as this batch is called by system's task scheduler). So it seems like the 'ForFiles' cmd is out.
Code, Attempt 2
I could go a more round about way of doing it, but simply retrieving the last modified date of the file (which in batch would return a string). I can truncate the string to the necessary date values, convert to a date, and then compare to current date. To do that, I've also looked into just using a for loop such as:
set myFile=\\myUNCpath\myFileName.csv
echo %myFile%
pause
FOR %%f IN (%myFile%) DO SET myFileDate=%%~tf
echo %myFileDate%
pause
Though my first debug echo provides the proper full file name, my second debug just returns ECHO is off., which tells me it's either not finding the file or the for loop isn't returning the file date. Not sure why.
I've also tried minor changes to this just to double check environmental variable syntax:
FOR %%f IN (%myFile%) DO SET myFileDate=%%~ta
Returns %ta
And finally:
FOR %%f IN (%myFile%) DO SET myFileDate=%~ta
Which without the extra '%', just crashes the batch.
I'm really at a loss at this point. So any tips or guidance would be greatly appreciated!
Using forfiles to a UNC path can be used using PushD
For just echoing the file older than x in UNC path, simply just use
PushD %myPath% &&(
forfiles -s -m %myFile% -d -6 -c "cmd /c echo /q #file
) & PopD
Here is one way how to use goto if file older than x found in UNC path using your examples.
if not exist "C:\temp" mkdir C:\temp
if not exist "C:\temp\test.txt" echo.>"c:\temp\test.txt"
break>"c:\temp\test.txt"
set myPath=\\myUNCpath
set myFile=myFileName.csv
PushD %myPath% &&(
forfiles -s -m %myFile% -d -6 -c "cmd /c echo /q #file >> c:\temp\test.txt"
) & PopD
for /f %%i in ("C:\temp\test.txt") do set size=%%~zi
if %size% gtr 0 goto next
:next
Huge thanks to both #Squashman and #MadsTheMan for the help. Luckily this batch finally is the piece of code that I can take to my boss to push switching over to at least using PowerShell!
Anyway, for those of you looking for the best way to get a UNC path file's modify date, here is what I've come up with. Not very different than other threads (and a thanks goes out to Squashman for spotting my missing " " in the for loop).
set myFile=\\myUNCpath\myFileName.ext
FOR %%f IN ("%myFile%") DO SET myFileDate=%%~tf
::And if you'd like to try to do long winded calculations you can further break the dates down via...
set fileMonth=%myFileDate:~0,2%
set fileDay=%myFileDate:~3,2%
set fileYear=%myFileDate:~6,4%
set currentDate=%date%
set currentMonth=%currentDate:~4,2%
set currentDay=%currentDate:~7,2%
set currentYear=%currentDate:~10,4%
The plan was to then convert the strings to integers, and then use a switch-case block to determine if the variance between dates was acceptable... blah blah blah.
Long story short - if you are limited to batch (and not creating secondary files -- such as a csv or the temp file suggested by MadsTheMan) you're going to have a really long script on your hands that still might have flaws (like leap year, etc unless you're adding even MORE code), when you could just make the comparison calculation using one line of code in other programs.
I am running below command to run Soapui Test suite and it is working fine
testrunner.bat -s"TestSuite4" "D:\Invesco\JP Groovy Code\ExploreGroovy.xml"
I ahve also used with below command and it is working fine as well
testrunner.bat -s"TestSuite4" "%USERPROFILE%\ExploreGroovy.xml"
Now I have added one Envrionment variable 'EnvP' and its value id 'D:\Invesco' and tried with following command but it is not working.
testrunner.bat -s"TestSuite4" "%EnvP%\ExploreGroovy.xml"
Can some one help me in this. I don't want to give hard coded path of any drive. Please suggest if anyone has any other solution.
Thanks.
the process starting testrunner.bat (probably explorer.exe?) must
know about the new variable. have you tried logging out and in again
after setting it?
if it is cmd, try finding the variable with set | find "EnvP". If it is not there, you need to start a new cmd session.
Use these commands and you should see why it fails:
#echo "%EnvP%"
#if not exist "%EnvP%\ExploreGroovy.xml" #echo Ouch!
#pause
testrunner.bat -s"TestSuite4" "%EnvP%\ExploreGroovy.xml"
#pause
For all my SoapUI projects I have multiple .bat scripts in the same location as the project.xml file to run different sets of test suites, and all of it goes into your source repository.
IF NOT DEFINED SOAPUI_ROOT SET SOAPUI_ROOT=%ProgramFiles%\SmartBear\soapUI-Pro-4.6.4
REM make certain we are where we _think_ we are
CD %~dp0
REM cleanup previous results
DEL /f /q *.log*
RMDIR /s /q results
REM run the tests
CALL "%SOAPUI_ROOT%\bin\testrunner.bat" -s"Smoke TestSuite" -fresults My-soapui-project.xml
REM determine if there are failures
IF errorlevel 0 (
ECHO All tests passed.
PAUSE
EXIT 0
) ELSE (
ECHO There are failures!
PAUSE
EXIT 100
)
Is there a way to specify the current working directory for the system command executed by the function module SXPG_COMMAND_EXECUTE?
I do not see any parameter which would allow me to do that either by defining the command in transaction SM69 or on the list of IMPORTING parameters in SE37.
It looks like by default such commands are started in DIR_HOME which can be viewed by the transaction AL11. Do I have any control over that?
There isn't a way of doing it via `SM69' unfortunately. I think the only solution is to create a script and call that.
I was going to suggest wrapping the statements in a SM69 command defined as a call to sh with parameters of -c 'cd <dir> && /path/to/command' but unfortunately that doesn't work. According to note 401095 wildcards are not permitted. When I tested, && was translated into a single &, causing the command to fail.
Would be good if you access this information using FM FILE_GET_NAME_USING_PATH (export the script name for which you want to find the physical directory).
The recieving path can be used in SXPG_COMMAND_EXECUTE.
Because the external commands I called were actually .bat files I solved this by putting the following expression at the beginning of each and every one.
cd /d %~dp0
This Stackoverflow question helped a lot actually.
I'm trying to run the following command in Windows Server 2003 but sed creates a pile of files that I can't delete from the command line inside the current directory.
for /R %f in (*.*) do "C:\Program Files\gnuwin32\bin\sed.exe" -i "s/bad/good/g" "%f"
Does anyone have any suggestions? Mysteriously enough, I'm able to delete the files using Windows Explorer.
As requested, here are some example filenames:
sed0E3WZJ
sed5miXwt
sed6fzFKh
And, more troubleshooting info...
It occurs from both the command prompt & batch files
If I just need to run sed on a single directory, then I use sed "s/bad/good/g" *.* and everything is OK. Alas, I also need it to tackle all the subdirectories.
I only have Sed installed.
Sed is creating the files
I have replicated your setup and I have the following observations.
I dont think there is a problem in the loop. The simple command "C:\Program Files\gnuwin32\bin\sed.exe" -i "s/bad/good/g" . - creates the same set of temporary files.
The files are indeed created by sed. sed creates these temporary files when the "in place" (-i) option is turned on. In the normal course, sed actually deletes the files (that is what happens in cygwin) using a call to the 'unlink' library. In case of gnuwin32, it looks like the 'unlink' fails. I have not been able to figure out why. I took a guess that maybe the unlink call is dependent on the gnuwin32 'coreutils' library and tried to download and install the coreutils library - no dice.
If you remove the 'read-only' restriction in the parent folder before executing the sed command, you can delete the temporary files from windows command prompt. So that should give you some temporary respite.
I think we now have enough information to raise a bug report. If you agree, I think it may be a good idea to bring it to the notice of the good folks responsible for gnuwin32 and ask them for help.
Meanwhile, the following version cleans up its temporary file:
https://github.com/mbuilov/sed-windows
As this is a known bug in sed with the -i option you can run attrib -R <filename> to remove the read only attribute from file after sed completes.
Alternatively do not use the -i option and redirect the output to a new file and then delete and rename the input and output.
Cygwin hoses the ACLs on files sometimes, you'll probably have to use cacls or chmod to fix it up before you can delete the file.
Here is where a bit of troubleshooting comes into play. Does this happen when you run that command from the command-line and a batch file? What if you run sed on an individual file on the command line - does it create these files for every file, or just certain files/filetypes? Does it only happen for that replacement, or all replacements in general, or just always when you run sed.exe on a file? Is it only sed creating these files, or all Gnuwin32 exe's (eg. awk, cat, etc)? Does the same thing happen on a sed.exe from a new install of Gnuwin32? What error message does it give when you try to delete the files? Can you delete the files from explorer while the command prompt is still open? What if you close the command prompt and reopen it, then try to delete the files?
you can just run sed without for loop
c:\test> sed -i.bak "s/bad/good/g" file*.*
This is a stab in the dark, but it wouldn't surprise me in the least if the gnuwin32 implementation of sed is duff (i.e., faulty in some way). Can you try to replicate the problem using the AT&T U/Win POSIX support for windows? It is easy to install and includes the Korn shell, sed, and find, so you can use find instead of the FOR /R. (I'm wondering if part of the problem is that the MS FOR and gnuwin32 sed don't play nicely together.)
I realize this is an old thread but It's still an issue. My fix is to add
"DEL sed*" to the end of a batch file after sed. Quick and dirty.
I am using this command to clean up the temporary files created by gnuwin32's sed:
FOR /f "tokens=*" %%a in ('dir /b ^| findstr /i "^sed[0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z]$"') DO del %%a
i know this is old. But just want to share with people what I did that cause this.
It was in fact the temp file for an already open file through gvim example .swap file that causing the sed tmp file didnt get remove completely.
So sed trying to read and append into the opened file which the user is currently viewing and having trouble doing it which causes the tmp file error.
I need to make a script that automates the following:
Read comma or tab separated values from the input file
Construct a command from them and run it
Get the command output, looks for substrings in it and update the log file based on the existence of a substring
I do this in Windows Server 2008, so I can do this in CMD or PowerShell but I am not sure they provide such possibilities. I can try Perl or C#, but I want to try a minimalistic approach first.
Minimalistic as far as coding - Perl
Minimalistic as far as installing new software - PowerShell (IIRS W.S.2008 included that?)
So many answers, and none providing a solution that would meet the requirements...
You didn't say what are the conditions to be checked against each CSV row, and what the CSV would be like, and what the log would be like - so I made it all up... Here's an example in BATCH:
#echo off
set csvfile=input.csv
set logfile=output.log
for /F "tokens=1,2,3 delims=," %%a in (%csvfile%) do call :processline "%%a" "%%b" "%%c"
exit /B 0
:processline
set param=%~3
set check=%param:um=%
rem if they are not equal - substring 'um' exists in it.
if not "$%check%" == "$%param%" (
rem this passes all params to output.
rem I'm not calling echo directly here, because there might be symbols, that will confuse CMD at the end of the %*.
call :output %*>> %logfile%
)
exit /B 0
:output
set colA=%~1
set colB=%~2
set colC=%~3
rem output to log
echo [%DATE% %TIME%] (%colB%) %colA% %colC%.
exit /B 0
Here's the example input file that I tested it with:
foo,1,dum
bar,3,dim
baz,15,dirum
And here's the resulting log messages:
[2009-10-14 14:57:35.87] (1) foo dum.
[2009-10-14 14:57:35.89] (15) baz dirum.
I hope this shows clearly, that BATCH is not nasty nor it is hard to use. :P
If you have further question about BATCH - don't be shy, post them all on SO. ;)
I would recommend going with Python (or Perl if you swing that way). These are very minimal tools to have to install on a machine and add all the functionality you need.
The string handling you describe is unpleasant in any shell (Bash included) unless you are using sed or awk... and that just gets esoteric. In the end you'll retain more hair if you go straight to a scripting language first.
Perl was called into existence to quickly solve these kind
of tasks. It should not take more 20 lines for this
particular problem.
It is also really easy to install:
Download ActivePerl (17.7 MB, Perl 5.10.)
Run the installer.