How to launch a .bat file in VB without associating the file with the program that launched it? - vb.net

Ok, the the question looks freakish, but this is sort of a continuation of the question I posted
here.
So, I create a .bat file in Visual Studio with certain lines and launch it, but it basically doesn't find the files it needs, but if I launch the .bat file it created manually, it works.
The problem, as far as I see it, is that the .bat file the program launches isn't the same as the one that is created in the folder?
The .bat files use the command line interface of Asesprite found here, e.g. :
#set ASEPRITE="C:\Program Files\Aseprite\aseprite.exe"
%ASEPRITE% --batch animation.ase --scale 2 --save-as animation-x2.gif
I'm not sure which part of the VB code I'd need to share, so ask if needed.
The error in .bat goes something like:
C:\Users\User\Desktop\aseConverter\aseConverter\bin\Debug>"E\Asesprite\asesprite.exe" --batch skeleton2_gib3.ase --scale 1 --save-as skeleton2_gib3.gif
File not found: "skeleton2_gib3.ase"
Error loading file "skeleton2_gib3.ase"
A document is needed before --save-as arguement
The first line should not be the Debug folder, but the location the .bat file was created in. I've no idea how to fix it.
It SHOULD be
C:\Users\User\Desktop\skeleton>"E\Asesprite\asesprite.exe" --batch skeleton2_gib3.ase --scale 1 --save-as skeleton2_gib3.gif

The problem here is that the batch file references files without path. Therefore the files must be in current working directory of the batch file.
But the batch file respectively command line interpreter cmd.exe is called by the VB.net without setting the working directory. Therefore the current working directory set by Windows for the batch file is the same as of the starting VB.net application.
But the starting application creates the batch file and the other files in a different directory, not in its own current working directory.
One solution is changing current working directory inside batch file to the directory the batch file is stored. This can be done by referencing argument 0 of the batch file which contains name of batch file with complete path.
What does %~dp0 mean, and how does it work? explains how to get drive and path of batch file.
Therefore one solution is to use a batch file like below:
#echo off
cd /D "%~dp0"
set "ASEPRITE=%ProgramFiles%\Aseprite\aseprite.exe"
"%ASEPRITE%" --batch animation.ase --scale 2 --save-as animation-x2.gif
See help output after executing cd /? in a command prompt window for meaning of parameter /D (change also drive if necessary).
An explanation for %~dp0 can be read on running call /? or for /? in a command prompt window.
Another possibility would be the usage of following batch code:
#echo off
pushd "%~dp0"
set "ASEPRITE=%ProgramFiles%\Aseprite\aseprite.exe"
"%ASEPRITE%" --batch animation.ase --scale 2 --save-as animation-x2.gif
popd
The difference to command cd is explained in help which is output in a command prompt window after executing pushd /?.
Best would be to create the batch file with all files referencing with complete path, name and file extension.

Related

make: Convert .pdf files in a folder to .txt files without using loops

I want to convert all .pdf files in a folder into .txt files with make without using loops and with the help of pdftotext. The new .txt files shall keep the original file name. Additionally, the new file gets a new file extension.
Example:
test1.pdf --> test2.newextension
Everything's written within a Makefile file. I start the conversion by typing in "make converted" in my console.
My first (miserable) attempt was:
converted:
#ls *.pdf | -n1 pdftotext
However, there are 3 things still missing with it:
It doesn't repeat the process
The new file extension isn't being added to the newly created files.
Is the original name being kept or being given to the pdftotext function?
I used to program with the bash and Makefile is completely new to me. I'd be thankful for answers!
You can refer to this simple example:
SOURCES ?= $(wildcard *.pdf)
%.txt: %.pdf
pdftotext $< $#
all: $(SOURCES:%.pdf=%.txt)
clean:
rm -f *.txt
If no SOURCE was defined, it'll just try to get all *.pdf files from the local directory.
Then we define a pattern rule teaching make how to make *.txt out of *.pdf.
We also define target all that tried to make a txt file for each .pdf file in SOURCES variable.
And also a clean rule deleting quietly all .txt files in current dir (hence be careful, potentially dangerous).

VB.NET - Shell batch file vs. Manually opening batch file = different results, for PSFTP.exe

I am using a Script Task in SSIS. So I am writing in vb.net. I have a substantial amount of code that ends up writing two files: one is a .bat file with this EXACT contents in it, minus I've changed hostname, username, and password of course:
C:\Users\ipisors\AppData\Local\Temp\091014121929_Phoenix\psftp.exe -pw PASSWORD -b C:\Users\ipisors\AppData\Local\Temp\091014121929_Phoenix\091014121929.txt USERNAME#HOST
(I'm sure it has this, because I manually check it after the Script Task runs).
The content of the .txt file referenced in the command is this EXACTLY:
cd uploads
cd OUT
mget PhoenixEnrollment_20140910*.txt
bye
MY QUESTION -
After the script task runs successfully, there is no downloaded file inside the directory of PSFTP.EXE (C:\Users\ipisors\AppData\Local\Temp\091014121929_Phoenix). Nothing.
However, if I manually double click on that same batch file that the script task was supposed to SHELL(), it immediately works perfectly. Within a few seconds, there is a downloaded file inside C:\Users\ipisors\AppData\Local\Temp\091014121929_Phoenix
What could possibly be the difference in reaction from the FTP server, between my script task code:
Shell(strBatPhoenix, AppWinStyle.NormalFocus, True)
(which by the way - yes I can actually see it working!)
and double clicking the same da*n file
I've also debugged the script task, it's definition Shelling out the EXACT SAME bat file.
Help please!
I will say the password to the SFTP site has a caret (^) in it, which I am escaping by using a double caret.
Figured it out after additionally testing one other way:
I used the command prompt itself to run my batch file. It ALSO did not download to the expected directory. I began to suspect that, even though the Shell was automating a batch file in the 'desired' folder......that batch file was then reading the 'local' directory as whatever calling application had initially Shelled it out.
In this case: c:\users\myusername. And therein was my file.
Lesson to be learned: Shelling a batch file, even if that batch file shells another file, may end up with one application or another reading your instant directory as the instant directory of the application that did the first shell, not the last shell.

Input Error when running WSH script

I'm trying to run WSH script using cscript specifically
in cmd I got this Error
Input Error: There is no script file specified.
using this command
cscript c:\file.wsh
On windows 7 ultimate
My WSH script simply writes a registry entry
I don't want to use vbscript (.vbs) or wscript engine
so how can I make my WSH script work ?
.WSH
The Windows Script Host control file (.wsh) is a text document in which you can customize the execution of one or more of your scripts. It is created automatically when you set the properties for a supported script file.
The following example illustrates a typical .wsh file:
[ScriptFile]
Path=C:\WINNT\Samples\WSH\showprop.vbs
[Options]
Timeout=0
DisplayLogo=1
BatchMode=0
The path information in the [ScriptFile] section identifies the script file that is associated with the .wsh file. The keys in the [Options] section correspond to settings in the Script tab within the Properties dialog box.
Note:
You must have the original script file present when executing the .wsh file. If the .wsh file fails to run the script, check the Path= information in the .wsh file to ensure that it points to the script you are attempting to run.
When you double-click a .wsh file or run it from the command line, CScript.exe or WScript.exe reads the .wsh file to determine the specific settings that should be used to execute the script. CScript/WScript executes the original script, passing in the properties that are defined within the .wsh file.
It's not possible to specify script parameters with the .wsh file. You must run the script (either the script file or the .wsh file) from a command prompt to add the parameters.
Resource: Setting and Customizing Script Properties (.wsh)

xcopy /d copy all files every time, even unchanged files

i try this command line
xcopy e:\myfolder /EXCLUDE:excludeList.txt \\192.168.158.15\public\comp\myfolder /E/I/D/R/H/Y
the command copy all files every time even unchanged files
i use /d that suppose to copy just newer files.
a small test shows it does work. you must have other problem ...
edit
in netwoek enviroment - you should add /z

Executing Love2D scripts

The only way I found out to execute my script with the Love2d framework is to zip all of it and then rename the zip to love. This kinds of take a lot of time for a small modification. Is there a faster way to do it? I tried to command line and I get this error
'love' is not recognized as an internal or external command,
operable program or batch file.
LÖVE also executes folders if they have the main.lua in them - you can just drag and drop the folder onto the application, or call it from the command line with the folder as the argument if you prefer.
LÖVE runs the contents of a folder if it can find a main.lua in it (Like Bill said).
[Note that it doesn't check subfolders].
There are three ways to run a love2D program, you can:
a) Drag the folder over the love.exe binary/link (This works in Win and *Nix, I don't know about OS X).
b) Navigate to the directory that is one level above the folder and type love [folder containing main.lua]
or
c) Zip it up and rename the .zip to a .love. Then double click the .love file
Option 'b' will fail if the binary is not in the %PATH%(Windows) or $PATH(*Nix) variable
(It will spout an error message like 'love' is not recognized as an internal or external command, operable program or batch file. on windows and bash: love: command not found on linux).
There are two ways to solve this:
(Both require ADMIN/root privileges, )
1) Add the love binary to the PATH variable. Here's how to do this in windows and in linux (In linux you want to do something like this: PATH=$PATH:$HOME/where/ever/you/put/love/)
2) You can add a link to the love2D binary in C:\WINDOWS\system32 or /usr/bin/.
In windows you create a shortcut to the love.exe (wherever you installed it to) and then drag it into C:\WINDOWS\system32. In linux you can run this:
sudo link /path/to/love/binary /usr/bin/love && sudo chmod ugo+rwx /usr/bin/love
I hope this helps!
Sources:
Google (the links above), Love2D and my knowledge :D
I found this to be very helpful when i started. Hope this helps
A Guide to Getting Started With Love2d
If you're using Mac OS, you should run using:
open -a love xxx.love
To recreate a file as .love, you can run in command line:
zip xxx.love file1.lua file2
If you just want to replace a file in .love:
zip -r xxx.love file1.lua
I think this will make your work easier.
simple way:
create folder /path/to/Game
put your files (main.lua, conf.lua, ...) in folder /path/to/Game
you can run script like this:
love /path/to/Game/
or if you use Linux, you can go in folder (cd /path/to/Game) and type just:
love .
(dot means that you want to run it form in folder
I found a simple solution for save time.
You have to create a file .bat with this simple command:
del Project.love
7z.exe a Project.zip ..\Project\*
ren Project.zip Project.love
For do this you need to download 7zip and insert this file (file.bat) into the folder of your project. Like this:
Good work!
If you're yousing Notepad++ to write your code, just open your main.lua file, then go to Run and add there this text including quotes:
"Path" "$(CURRENT_DIRECTORY)"
Where Path is a Full path to love.exe.
The save it to a key combination and now you can test your code by using this combination in any script at Notepad++.
If you use Sublime Text, you can make a build which runs your application.
https://love2d.org/wiki/Sublime_Text
While in Sublime Text press CMD + B or Ctrl + B