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

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.

Related

Batch run maya with last recent file

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)

Can't open a .chm file from a batch file

I am trying to open a .chm file from a batch file.
The batch file has only this text in it :
echo off
start "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm"
If I run the batch file, the commandline opens but nothing further happens.
If I copy paste S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm in start menu/run then it does works.
If I make a shortcut with target "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm" then it also works.
So the command works everywhere, except from a batch file.
What am I doing wrong here ?
It might also be important to know that when I start it from the shortcut, or start menu/runI always get a dialog
We can't verify who created this file. Are you sure you want to open this file ?
I am using Windows 7
EDIT
My problem is not the dialog, my problem is that nothing happens when I open the chm file from a batch file
The Start command is probably seeing your doublequoted string as a title, enter Start /? at the command prompt for its usage information.
Try adding an empty title first:
#Echo Off
Start "" "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm"

How to run a text file as an executable without changing filetype

I was wondering if I could save an executable (windows) as a text file and then run it without changing its filetype extension.
I have researched a bit but haven't found anything specific.
I would like to run a vb script that "launches" the text file.
Let someone else (in this case, cmd) launch the txt file.
WScript.CreateObject("WScript.Shell").Run "cmd /c mytxtfile.txt", 1, false
But you can use cmd, runas, psexec, ... but you can not directly use vbscript to start a .txt file as a process unless .txt files are not a registered file type in windows.
CMD.exe passes any file it doesn't know to CreateProcess. CreateProcess looks in the file to see what to do with it, it doesn't use extensions. Therefore unknown file types can be executed by typing the full filename in a command prompt. If the filetype is registered then then cmd will do that rather than pass to CreateProcess.

Build output from Visual Studio 2010 external tools in output window

I run a batch file as an external tool (by adding it in Tools->External tools) in VS2010 (I've checked the "Use Output Window" option). This batch file performs compilation as in VS command prompt. The project that I'm working on has makefiles for various folders, so I use the mk command to build.
In the batch file, I set up the VS environment and then run the following commands:
cd $directoryWhichContainsFileToBuild
mk
cd main //This directory contains the executable that is to be built
mk
I see the output of the first mk in the Output window but after that it just hangs. I also tried to use an echo after the first mk but even that doesn't get printed in the output window (the ones before it can be seen).
Somewhere I read that there is an issue with VS 2010 output window where it hangs after showing some output, although I couldn't really be sure that that is what's the issue here.
Do I need to enable some other VS setting? Has anybody else encountered this issue?
Thanks.
Update: I unchecked the "Use Output Window" and "Close on exit" option, and I see an extra statement: "Press any key to continue". On doing that however, their is no further processing of the batch file.
Update2: Got it to work by prefixing mk with "call".
Thanks all who tried.
It is always good in batch files to specify executables with full path and file extension instead of just the file name. This avoids often lots of problems.
Here was just mk used instead of mk.bat. Therefore on every compile the command line processor cmd.exe searches for mk.* and then checks if any of the found files have an extension listed in environment variable PATHEXT. The order of file extensions separated by a semicolon in PATHEXT defines the order of execution in case of a directory contains multiple mk.* files.
If a command being specified in a batch file not being an internal command of cmd.exe without path, command line processor searches first for a file with given name in current working directory. This is often one more cause of error. What is the current working directory on execution of the batch file?
Next if no file to execute can be found in current working directory, the command line processor searches in all folders being listed in environment variable PATH separated by semicolons.
So specifying in batch files edited only rarely an external application or another batch file with full path, file name and file extension, in double quotes if necessary because of 1 or more spaces in path or file name, helps command line processor to more quickly execute that application or batch file and avoids problems because of executable not found (unknown command).
Sure, when typing commands in a command prompt window, nobody wants to enter the executables with full path, name and extension. But for batch files it is always good to be not lazy and type files to be executed with full path and extension.
TripeHound has given already the explanation why the observed behavior occurred here.
If a batch file is executed from another batch file without using command call, the command line processor continues batch execution in the other batch file and does never come back. In a C/C++ program this is like using goto with the difference that parameters can be passed to the batch file containing the further commands to be executed next.
But running from within a batch file another batch file with call results in continuation of execution below the line calling the other batch file once the other batch file reaches end, except command exit is used in the called batch file without parameter /B.
So the solution here is using:
cd /D "Directory\Which\Contains\File\To\Build"
call "Path\Containing\Batch\File\To\Build\mk.bat"
rem With mk.bat not changing current working directory change working
rem directory to the directory containing the executable to be built.
cd main
call "Path\Containing\Batch\File\To\Build\mk.bat"
BTW: exit exits command processor, exit /B exits just current batch file. I'll give you three guesses why the parameter is B and not a different letter. Yes, B is the first letter of batch.
Writing as a separate answer instead of an update in the question itself as many readers see the header and skim to the answer: got it to work by prefixing mk with "call". (#TripleHound has also posted the conceptual reason for it in the comment above.)

help with windows batch scripting basics - execution and calling a separate executable within the script

Newbie to windows scripting. I need help running the .bat file on the command line so I can test it.
I used Text Document as my editor to create the file (opens up also as Notepad).
I performed file "save as" (ALL FILES). If I open up cmd, I can see the file has a .txt extension (myfile.bat.txt). So if I just type in cmd myfile.bat.txt the editor opens. I am not sure how to execute this correctly.
As for the logic in my batch script, I am basically logging into a remote directory (already created the net mount) and now I want to:
run an executeable file
rename some files.
With some research, I written this so far. I have saved it as a .bat file
# echo off
echo This is a batch file to run an executable and rename some files
pause
--run executable file here, just don't know how to do it
x:
cd x:
rename fileA fileB
Any help, good tips/practice would be great. Thanks.
Type in this command in cmd window:
rename myfile.bat.txt myfile.bat
Now you can run the script by simply invoking:
myfile.bat
or
myfile
(provided there's no myfile.exe or myfile.com in the same directory).
If you need to edit the script further, you can either right click it in Explorer and choose Edit or call the editor from the command window:
notepad myfile.bat
To call a program from the script, simply add its name, if it's in the current directory:
someprogram.exe
or the name with the path, if it's somewhere else:
directory\program.exe
or
d:\directory\program.exe
If the name or the path contain spaces, be sure to enclose the entire name & path string in double quotes:
"d:\directory\program name.exe"
you can just type the full name of the program
eg
"c:\program dir\program.exe"
or you can add the program directory to your path environment variable
set PATH=%PATH%;"c:\program dir"
and just type the program name
program
you can also edit your PATH variable in windows http://support.microsoft.com/kb/310519
NOTE: When you save the file in notepad, you want to save it as filename.BAT and select All Files from the second dropdown. If you don't it still gets saved as a .TXT.
A couple of command to consider:
CSCRIPT cscript /? in CMD
START http://ss64.com/nt/start.html
If you're doing say a VBSCRIPT use CSCRIPT to start it. If you're trying to execute another BATCH script or an EXE, use START

Resources