Batch run maya with last recent file - command-line-arguments

I try to make a batch file that basically opens all the stuff I need to work. Opening Maya is quite simple, but there's one step further i'd like to do: make it open my last opened file.
if i understand the doc Start Maya from the command line
I could try this:
path/to/maya.exe -command [some MEL commands that may open the last opened file]
But I have no clue how to MEL and I guess for it to work as a windows batch I must keep it as one command line. I try to read the docs but I fail to find anything I can make use of.
python("recent = cmds.optionVar(q='RecentFilesList')[-1]; cmds.file (recent, force=True, open=True)")
Issues:
I can't find a way to correctly parse the quote marks through batch to Maya.
The file command requires to first save the file to work...
Solutions
Thanks to this answer:
use force=Truein cmds.file (recent, force=True, open=True) to force the file command to work without the need to save the file first
use one backslash \ before the commands " to properly parse them to Maya
"path\to\maya.exe" -command "python(\"recent=cmds.optionVar(q='RecentFilesList')[-1]; cmds.file (recent, force=True, open=True)\")"

Usually you replace a " with a \" to get a working mel command. So if you this could work:
"python(\"recent = cmds.optionVar(q='RecentFilesList')[-1]; cmds.file (recent, open=True)\")"
But to be honest I did not test it as a commandline argument.
You can modify the file command with force:
cmds.file(recent, force=True, open=True)

Related

How to run PSPP syntax file from the command line (CMD)?

I have the following syntax written in PSPP .sps file:
GET FILE = '... result.sav'
save translate
/outfile = '... data.csv'
/type = CSV
/REPLACE
/FIELDNAMES
/CELLS=LABELS.
where ... stand for the path of the files.
The Script works as expected, so when I open PSPP and run it, it opens the first file and saves it as another CSV file. However, I would like to do two more things:
Call this file from CMD (in Windows) so it will execute all command automatically and silently, without showing the PSPP windows.
Add a line to the syntax to terminate PSPP after execution.
Right now I can only type the name of the .sps file in the CMD and it opens it but does nothing else. I have looked in the official docs but couldn't find any solution for that.
Well, I found the answer myself:
In CMD I had to type:
"C:\Program Files\PSPP\bin\pspp.exe" C:\Users\...\Dropbox\MATLAB\atid\convert_to_csv.sps
And that's all. It runs PSPP in silent mode and creates the file as needed.
What I didn't know was that I need to first write the path of PSPP .exe file ("C:\Program Files\PSPP\bin\pspp.exe") before the name of the syntax file. All the rest just worked.

How do I automate an input answer in a batch file

So I have been working on a simple batch file, that thanks to #Magoo, I was able to solve the first question I had about it.
Now my next question,
Is there a way to automate an answer input.
Since I'm running Windows 7 (this is the current course I am on, in my quest to become a knowledgeable IT guy), I cannot use PowerShell to extract an image, and to my best knowledge, PowerISO is the only program I have found where I can use command lines in a batch file to extract the .iso file that I want, and place it on the drive/directory that I want. However, I came across the need to input an answer 'NoAll' before I could finish the extraction. I'm wondering if there is a way to automate that answer, if needed. It will only be used once, as the NoAll implies.
All the code is correct and the batch file works properly barring this one little hiccup.
Here's my batch file.
echo
cd "C:\Program Files\Windows AIK\Tools\PETools"
call copype amd64 "C:\winpe-amd64"
copy "C:\winpe-amd64\winpe.wim" "C:\winpe-amd64\iso\sources\boot.wim"
copy "C:\Program Files\Windows AIK\Tools\amd64\imagex.exe" "C:\winpe-amd64\iso" & cd "C:\Program Files\Windows AIK\Tools\amd64"
oscdimg.exe -n -bC:\winpe-amd64\etfsboot.com c:\winpe-amd64\iso c:\winpe-amd64\winpe-amd64.iso
cd 'C:\program files\powerISO"
piso extract "C:\winpe-amd64\winpe-amd64.iso" / -od f:
as the extract begins to run, I get a prompt for input, and this is where I would like to be able to automate the 'NoAll' answer.
Thanks in advance!
Since all you need to do it input text, you can simply echo what you want to type and then pipe it to the other command.
echo NoAll|piso extract "C:\winpe-amd64\winpe-amd64.iso" / -od f:
You can use the input file and input redirector '<' to automate most of input. For example, create a text file 'NoAll.txt' with the content "NoAll" (without quotes, and add a newline at the end for 'Enter' key). On the command that needs NoAll, execute it as follow:
piso extract "C:\winpe-amd64\winpe-amd64.iso" / -od f: < NoAll.txt

How to create an executable command prompt script

I usually perform actions in the 7zip command line program. I was thinking about creating a small script to do everything automatically, but I have never written any Windows shell script before and therefore don't even know where to begin.
I would like to make an executable script file which, when a user double-clicks on it, will call the 7zip command line and perform some actions.
First of all, is this possible? And if it is, what is the best way to do this?
You can create a batch script to do this.
It's basically command line commands that run one after another so you don't have to keep typing them in :)
Put the commands you would normally use for 7zip in a notepad file and save it with the extension .bat, then run it.
7z blah blah params
7z more params and args
All your commands will be executed automatically when the previous one finishes.
There are other programming languages you could do this in (or even VBScript) but batch would be perfectly suited to this, and you don't need to install anything extra.
Batch files can run a series of command line commands. Simply create a text file and name it with the .bat extension.
There are plenty of resources on the internet which will provide you with help.

Windows .bat file doesn't execute its sequence

I created a simple install.bat file into my application folder, to execute its thing on windows.
But it only executes the first line of the .bat file.
Is there something that I need to add so it continues after the first one is done?
copy something somewhere
move something somewhereelse
gem install etc
Above are the type of commands that are in the .bat.
Do I need to anything something inbetween?
Is the first command in your batch file actually a copy command, or is it a command that's running another batch file?
Running a batch file from another by simply using the second batch file;s name will not return to the calling batch file.
If you want one batch file to invoke another and return you have to use the call command.
Are you overwriting a file? If so you'll need to add the /Y to the copy command to supress the prompt that asks if you want to overwrite the file.
Use the /h parameter to get help on the copy command. It will show this usage and some others.
As written above, all three lines will execute. I imagine that the second and third lines are failing. You should capture the output which will explain why those lines failed.

starting a windows executable via batch script, exe not in Program Files

This is probably batch scripting 101, but I can't find any clear explanation/documentation on why this is happening or if my workaround is actually the solution. So basically any terminology or links to good sources is really appreciated.
So I have a program I want to execute via batch script (along with several other programs). It's the only one where the exe is not in a Program Files folder. I can get it to start like this:
C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe
But I get an error along the lines of:
Run-time Error '3024':
Could not find file
C:\Users\MyUserName\Desktop\ModuleSettings.mdb
So it seems that the program is looking for its settings files from the same location that the batch script starts up. Given that I finally got everything to work by doing the following:
cd C:\WeirdProgram\WeirdProgramModule\
weirdmodule.exe
That works fine, and it's not the end of the world to have to go this route (just one extra line), but I've convinced myself that I'm doing something wrong based on lack of basic understanding.
Anybody know or can point me to why it works this way?
Oh, and doing the following:
start "C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe"
doesn't do anything at all.
Thanks,
you are doing it perfectly :-)
the executable is probably looking for this file in the "current working directory", which is being set, when you "cd" to it before.
you can set your working directory manually by creating a shortcut to your batch file; right click; properties.
edit:
you can also set your current working directory using the start command:
start "Title" /D "C:\WeirdProgram\WeirdProgramModule\" "weirdmodule.exe"
edit:
If you like to pass params, just add them to the executable filename as you would in a regular shortcut:
start "Title" /D "C:\WeirdProgram\WeirdProgramModule\" "weirdmodule.exe" "param1 param2"
or
start "Title" /D "C:\WeirdProgram\WeirdProgramModule\" "weirdmodule.exe param1 param2"
For reference, the syntax is described here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true.
What's happening is that weirdmodule.exe is looking in the "current directory" for the .mdb file. You might be able to tell it where to find the .mdb file through a command line parameter or some other configuration method (registry or .ini file maybe). How you'd specify the location is entirely up to the weirdmodule.exe program, though.
Other than that, your current workaround is probably what you're stuck with.
As far as your problem with using start.exe... the start.exe program has the very, very odd behavior (bizarre behavior in my opinion) of treating the first parameter as the 'title' to put in the window if (and only if) the first parameter is in quotes. So you have a couple of options:
Don't use quotes to specify the program. This works for you because you don't need quotes (there aren't any spaces or other special characters in the path that would require quoting it):
start C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe
Give an empty (or some other string) title as the first parameter. This is something you'd have to do if your path required quotes:
start "" "C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe"

Resources