AHK Run command with directory path containing space - autohotkey

Using AHK script to open up and launch text files (or script files) within notepad++. I recently had to add spaces to my file path which has caused the problems I now experience. It's as if the space in the file path is escaping the command.
e.g.
Run % "notepad++.exe C:\C Docs\SW\AHK\Desktop1.ahk"
Upon running the above line, it will ask in msgbox: "C:\C" doesn't exist. Create it?
This script happens to be the script location itself. So I also tried the following without success (produces same message):
Run % "notepad++.exe " . a_scriptdir . "\" . A_ScriptName

You are passing two arguments to Notepad++ the first one being C:\C and the second one being Docs\SW\AHK\Desktop1.ahk.
To pass them as one argument, do what you'd always do with command line arguments, quote them.
Run, % "notepad++.exe ""C:\C Docs\SW\AHK\Desktop1.ahk"""

Try like this:
Run notepad++.exe "C:\C Docs\SW\AHK\Desktop1.ahk"

Related

Difference between calling command line directly or from makefile

I have a confusing problem concerning mingw make and windows command line (Win7):
I have a makefile which shall call a vbs file to convert .vds files to .png files. here is the code of the makefile (without the defined variables, you can see the result in the picture below).
VSD2PNG: $(VISIO_OUTPUT)
#echo *** converting visio files to png files finished
define vsd_rule
$(1): $(call FILTER_FUNCTION,$(basename $(notdir $(1))),$(VISIO_FILES))
$(VSD_SCRIPT) $$< $(VISIO_OUTPUT_DIR)
endef
$(foreach file,$(VISIO_OUTPUT),$(eval $(call vsd_rule,$(file))))
leads to
As you can see, the command should call .\tools\visio\convert(.vbs) with two arguments (input file & output directory). Surprising is that the same command executed in windows command line works fine. I tried some modifications to solve the problem (unsuccessfully):
adding file extension to vbs-script leads to error 193, but I cannot find out, what that means.
calling the script without any arguments should lead to a runtime-error in the script, but that leads to make error -1 again (or with file extension 193).
using absolute path for script
Does anybody know more about the differences between calling a script directly from command line or from makefile, which should usually lead to the command line?

finding a files path in the command line

I am doing a batch scripting assignment where I have to call one script from inside another. I need the script to run the second script no matter where my lecturer saves these scripts. How would I do this. Is there some way to find the path of script inside the script and use that to execute the file. Any help would be great. I think I need to use %'s but i'm not sure.
The name of the script is Hello World.bat.
How would I copy Hello World.bat to the C:\ if I don't know which directory the lecturer has placed it in. what command/s would I use so that the copy would work regardless of the scripts location.
I don't see the "DOS" tag, but I'll assume that it is for now. If you want the entire path, you can get it by doing this:
echo %cd%
If you want just the last folder, this works (inside a .bat file):
for %%* in (.) do #echo %%~n*
Note that from the command line, the above command will work with single %'s:
for %* in (.) do #echo %~n*
If the script you are executing is calling other scripts in the SAME folder location, you can prefix the path statement with "%~dp0" or "%~dps0" but do not put a backslash between that and the name of the script you are calling. In other words, if script1.bat is calling script2.bat in the same folder, the statement in script1.bat would refer to "%~dp0script2.bat"
sorry about batch files, am not familiar, but in nix shell, there is the locate command which can return the path of the file , if you know the filename exactly and the name is unique.
like
name=$(locate filname)

prevent the problem of space in windows folders in the command line

As we know that windows, we can create folders with a name contains spaces(Hello World,New Folder,My Programs). In the commandline if we use start c:\Hello World\mygame.exe , it gives error called Hello is not found. it split the word from the space, to avoid this we can use thid start c:\"Hello World"\mygame.exe. my problem is this set x=%cd% (Here cd is "c:\Hello World" ) and we execute mygame.exe using this command "start %cd%\mygame.exe" which gives error of Hello is not found. Anyone knows solution for this?
Instead of putting quotes around just part of the path, put quotes around the entire path. If you do that, you should be fine.
start "%cd%\mygame.exe"
In the set command put quotes around the whole assignment:
set "x=%cd%"
In the start command, use quotes as well:
start "%x%\mygame.exe"
for example, if you have a folder name FOO FOO with a space and you want to access from cmd yo just do:
cd "FOO FOO"
That's all

Running a perl script in a batch file

i have a perl script that is used in updating my awstats logs of my website. The script works fine if i just paste it in cmd (Windows) but the moment i paste it in a batch file, it messes up the format of the files generated (they should be prepended with current date/time). The code is:
perl C:\PROGRA~2\AWStats\tools\awstats_buildstaticpages.pl -config=mywebsite -update -awstatsprog=C:\PROGRA~2\AWStats\wwwroot\cgi-bin\awstats.pl -dir=C:\myfolder\stats\reports -builddate=%YYYY%MM -buildpdf=C:\PROGRA~2\HTMLDOC\ghtmldoc.exe -staticlinksext=asp`
The resulting files generated is mysite.201008.asp if i paste it in cmd and execute BUT In a batch file with the same script, my resulting file is mysite.MM.asp.
Any idea why this is happening?
The problem is caused by %YYYY%MM.
"%" is a special symbol in batch files. You need to escape it by doubling it: %%YYYY%%MM.
It appears you have to escape the '%' characters.
The command shell doing variable substitution on %YYYY% which I'm guessing is not defined in your environment, so it substitutes the empty string for that "variable".
Unfortunately, there are no opaque quotes in the Windows shell.

Calling a software from Matlab

The command prompt works well in all respect of running the software as well as generating reports and output files. To generate an ouput file containing the desired result, we have to run the executable of the report program which uses a parameter file. For example if I were to implement these steps in command prompt, it would be like this:
“path\report.exe” –f Report.rwd –o Report.rwo
The output file is Report.rwo, this file will contain the variable exported.
Now to implement this in Matlab, below is a small script giving a gist of what I am trying to achieve. It calls the software for each run and extracts the data.
for nr=1:NREAL
dlmwrite(‘file.INC’,file(:,nr),’delimiter’,’\n’); % Writes the data file for each run
system('"path\file.dat"'); % calls software
system('"path\Report.rwd" –o "path\Report.rwo"'); % calls report
[a,b]=textread(‘"path\Report.rwo".rwo’,’%f\t%f’); % Reads the data and store it in the variable b
end
So I have two problems:
1) When I run this script in Matlab, it does not generate output file Report.rwo. Consequently, it gives an error when it reaches the line containing 'textread' function because of absence of the file.
2) Everytime Matlab calls a report (.rwd file), it prompts me to hit enter or type 'q' to quit. If suppose there are hundreds of files to run, then for every file I would be prompted to hit enter to proceed. The following line causes the prompt:
system('"path\Report.rwd" –o "path\Report.rwo"'); % Calls report
OLDER EDIT: There are 2 updates to my problem as follow:
Update 1: It seems that part 2 of my problem above has been resolved by Jacob. It is working fine for one run. However the final outcome will be confirmed only when I am able to run whole of my program which involves running hundreds of files.
Update 2: I can run the software and generate output file using command-prompt as follow:
**“path\mx200810.exe” –f file.dat**
This command reads the report parameter file and generates output file:
“path\report.exe” –f Report.rwd –o Report.rwo
LATEST EDIT:
1) I am able to run the software, avoid the prompt to hit the return key and generate the output file using Matlab through the following commands:
system('report.exe /f Report.rwd /o Report.rwo')
system('mx200810.exe -f file.dat')
However, I was able to do it only after copying my required .exe and .dll files in the same folder where I have my .dat file. So I am running the .m file through the same folder where I have all these files.
2) However there is still one error in Matlab's command window which says this:
"...STOP: Unable to open the following file as data file:
'file.dat'
Check path name for spaces, special character or a total length greater than 256 characters
Cannot find data file named 'file.dat'
Date and Time of End of Run: .....
ans = 0"
Strings enclosed in " .. " are invalid in MATLAB so I do not know how your system functions can even function.
Replace all " with ' and then update your question and include the command line arguments (e.g.-f file.dat) inside the quotes as below:
%# Calls software
system('"path\mx200810.exe" –f file.dat');
%# Calls report
system('"path\report.exe" –f Report.rwd –o Report.rwo');
Update:
Here's a cheap trick to solve your second problem (type q to terminate the program):
%# Calls software
system('"path\mx200810.exe" –f "path\file.dat" < "C:\inp.txt"');
%# Calls report
system('"path\report.exe" –f "path\Report.rwd" –o "path\Report.rwo" < "C:\inp.txt"');
Create a file (e.g. C:\inp.txt) which contains the letter q followed by the return character. You can create this by opening Notepad, typing q, hitting the return key and saving it as C:\inp.txt. This will serve as the "input" report.exe seems to need.
Change all the system calls in your code so that the input from the text file we just made is piped into it. I've included the modified calls above (scroll to the end to see the difference).
Use both outputs to get status of system run and text result, if any will be available.
cmd_line = '“path\report.exe” –f Report.rwd –o Report.rwo';
[status, result] = system(cmd_line);
Continue your script depending on status variable. Stop if it over then zero.
if (status)
error('Error running report.exe')
end
[a,b]=textread(...
If your parameters are variable you can generate the command line string in MATLAB using string concatenation or SPRINTF function.