I have a batch file with a single line in it:
src/Filé.txt
When I run the batch file (either in the command prompt or by clicking it in Windows Explorer), I get the following:
C:>src\FilΘ.txt
'src\FilΘ.txt' is not recognized as an internal or external command, operable program or batch file.
It turned my é into an Θ! I've also had it turn into an 8 on another occasion.
The file I'm trying to access does actually exist. Further, if I try it on a simpler file name (file.txt) it opens it without any problems. I'm running Windows 7 64 bit. Any idea what's going on here?
You should be able to edit the batch file and add the following line to the very top of the file:
CHCP 65001
This will set the character set to UTF-8 and should display special characters correctly.
Related
I have written a simple batch script which loops a directory and echoes some details about each file.When I view its results in the CMD terminal or output it to some file, I can view the results as expected.
The problem comes with PostgreSQL: when I try to import its results into a table, executing the following command:
copy schema.table(field) from program 'C:\\...\\my_bat.bat' with CSV header delimiter E'\t';
It imports 0 results, whereas if I run the same command pointing to a similar batch file in another directory, it works as expected.
What's going on? I am using windows.
Update: I have tried running the copy command calling program again on another batch script and this time, only a part of the string output is being imported.
The service user postgres needs sufficient permissions to run the program.
I remember that it was hard to change settings for that account on windows XP, I have not tried on more recent windows - service users are hidden by most GUI tools.
I've got a bat script that does a few cmds and also runs a stack of powershell scripts. Sometimes it errors out on the second or third command because it's cutting off a few characters. It's also done this on xcopy commands following a powershell script and vice versa. So here is an example:
Bat file:
xcopy "\\server\####\####\######" "C:\######" /S/I/E/Y
powershell "C:\SetupVM.ps1"
output:
\\server\Hard Disks\******.vhdx
\\server\Virtual Machines\*******.XML
2 File(s) copied
C:\Users\*****>rshell "C:\SetupVM.ps1"
'rshell' is not recognized as an internal or external command,
operable program or batch file.
Has anyone seen this before? Any ideas on how to avoid it?
Try opening your batch file in Notepad, and then 'Save As...' and be sure to select the ANSI encoding. Then don't touch it in your other editor :D.
It seems related to this issue.
I ran into this trying to write a batch file in Atom, and I think it was automatically encoding it to UTF-8. Opening in Notepad and re-saving it using ANSI encoding solved it for me.
A complicating issue for me was that my script was switching back and forth between git branches during my batch file, and if the batch file was different between the branches it would start to execute only partial lines as the computer would try to pick up the next piece of the batch, and it was causing the same issue.
From what I can see, the command line does not recognize the 'rshell' command.
Check your enviroment variables or start the command from where 'rshell'.com/.exe is located.
Other than this there is not much to say without seeing the content of the powershell script...
Basically I am just trying to create a batch file to copy one file from one location to another location in Windows XP like the code below but failed. May I know why?
copy C:/Directory_A/the_file D:/Directory_B
When I execute the batch file I see this in the output:
The syntax of the command is incorrect.
Try using backslashes
copy C:\Directory_A\the_file D:\Directory_B
I have a executable that when double clicked opens in a command line window.
Now there is a input file (i.e named "sphere_15000.inp") in the same directory where the executable apame_win64.exe is located. So we can inter the file name in the command line.
The question is how this can be done from mathematica front end? With the RunThrough command I tried to do it with no avail.
RunThrough["Executable Location", "sphere_15000"]
Do I need to put this file location in my Windows 7 environment path variable? Hope for some suggestion in this regard.
UPDATE
Found a solution to my problem.
First set the Mathematica directory to the folder where the executable is located.
path="C:\Users\FlowCrusher\Desktop\CUSP solver\Apame_build_2011_01_09\solver";
SetDirectory[path];
Then use the following style of input.
Run["\"\"apame_win64.exe\" \"input\"\""]
Here "apame_win64.exe" is the executable one want to run and "input" is the input file for the executable. This solves the problem. But a new item in the wishlist.
Is there a way to hide the console window in the background?
Here is how it looks on my screen.
As Chris suggested if we use minimized console in the Run command we get a minimized window but the program does not execute.
I hope that a solution exists.
BR
Yes, you might put the folder of you executable into the Path variable, or provide the full path name.
However, RunThrough seems to have been superseeded (on Windows) by
Import["!command ","Text"], which will execute command and read the comaand line output into Matheamtica as a string.
E.g.:
Export["testit.txt", "bla", "Text"];
Import["!dir" <> " testit* > dir.log", "Text"];
FilePrint["dir.log"]
--
Otherwise, I also had good results in the past using NETLink (not sure if WScript.shell
still works on Windows7/8 or if one should use something else).
Emulating Run (RunThrough is not really needed I think):
Run2[cmd_String] := Module[{shell},
Switch[$OperatingSystem,
"Windows",
Needs["NETLink`"];
shell = NETLink`CreateCOMObject["WScript.shell"];
shell # run[cmd,0,True],
"Unix",
Run # cmd,
"MacOSX",
Run # cmd ] ];
Can you run your application with input from a basic command window instead of the application console? This might be the form of command you would need:
apame_win64 -input sphere_15000.inp
or simply
apame_win64 sphere_15000.inp
You can probably check the available switches by running apame_win64 -help
A multi-part command can be run from Mathematica, e.g.
Run["type c:\\temp\\test.txt"]
Alternatively, also returning output to the Mathematica session:
ReadList["!type c:\\temp\\test.txt", String]
I landed here wanting to run abaqus command line on windows.
The solutions provided here worked out for me (Windows 7, Mathematica 9):
SetDirectory#path;
Run["start /min abaqus job=" <> fileName <> " interactive ask_delete=OFF >> log.txt"]
(Here the abaqus option ask_delete=OFF overwrites an existing simulation results and the >> redirects all the output to a file)
I think, minimizing the window did not run in your case since the executable throws open that window. In that case, this might be of some help
How do you make a .com file for MS-DOS? I have my own "operating system", PowerOS, and I want custom commands to be able to be entered. Is there any way to write a .com file?
The answer is fairly straightforward. You make a .COM file containing an MS/PC/DR-DOS program image by writing a program in a programming language and compiling it with a compiler that targets MS/PC/DR-DOS. That's it.
Don't get confused about filename extensions. There's a .COM program image file format, which is a fairly basic program image format. It was superseded by the "MZ" program image file format back in the 1980s. But it has nothing to do with the filename extension. A program image file for MS/PC/DR-DOS can have either the extension .COM or the extension .EXE, but the actual image file format is not dictated by this. (I mention DR-DOS. If memory serves correctly: In DR-DOS version 6 practically all of the program image files, even the ones named .COM, were actually "MZ" format executables, and compressed ones at that.)
What you do depends from what program image file formats your operating system's program loader is capable of understanding. And, really, only you can tell the world that. If your operating system's program loader understands the "MZ" executable file format, and the programs that run on your operating system are 16-bit and run in real mode, then compiling commands for your operating system is as simple (ignoring system call and library issues) as, say, cranking up OpenWatcom's 16-bit compiler+linker, wcl, and telling it to target MS/PC/DR-DOS with the -bcl=DOS option.
Of course, if your programs are 32-bit and your operating system runs them in protected mode, or even if your programs are 16-bit and your operating system runs them in protected mode, then the "MZ" file format will be unsuitable for your needs, and you should use one of the several alternative program image file formats.
I know that for windows 7 and most likely for the other windows OS's you can write either a .bat, .exe, or .com and place it into windows/system32 folder. That file can be used as a command from the command prompt by simply typing in the name of the command you made.
To take in command line parameters, a batch file can use the variables %1, %2, %3 etc. The command works like any other command and can be used to further write batch files with it.
As far as MS-DOS goes, you may be able to place one of those file types in the root directory or find where the other commands are placed and put it there. I am not sure if a COM file is required, but if so, there are batch to com converters out there such as this old school one:
Converter from batch to com
you can make an .bat file and paste this code to make custom commands
example:
#echo off
set /p command=
if %command% ==
in the code type your command at the end and what you will the command to do.
you can copy the if command to ad more commands