Use system command to download XML file - windows

I am writting expansion programs to a CAD program called 12d Model. The language I write these expansions in is simply called Macro language and it has a very limited API. So it doesn't have a way to find a file on Windows, list all files in a directory or download a file.
To overcome this I use simple ShellExecute and system calls. For example to list all files in a directory I use the system call "dir C:\ /B > C:\MyCurrentFolder\outfile.txt". One of my needs is to download and parse an XML file but the API has no download function.
Is there a system call to download a file from a URL? Is there some native way to do this? Maybe there is a Windows Application like regedit.exe or something that I can use to download a file?
If not, do you think it would be possible to do it through a batch script?

Windows does have built in FTP support using ftp.exe. So if you could find a FTP mirror of the file, or upload it to one yourself, that might work.

Yes there is a native way to do this. Use the msxsl.exe parser to download the xml file and save it to whatever location you would like. You can do this from the command prompt or from a batch file. Note the one caveat to this is you will need to use an xsl file that does not alter the xml file. The command would look something like this...
c:\msxsl.exe c:\myXML.xml c:\myXSLT.xsl > c:\myXML.xml
Note here the file located at c:\myXSLT.xsl cannot change the source file c:\myXML.xml

Related

Need to create/delete text file in Unix box from windows

I have a requirement where i need to create and delete a text file on unix from my windows server where i have informatica installed.
Using workflow i was able to place file in unix but not able to find a way to delete already existing file.
Also the client does not want us to download any additional software like putty on windows server.
Please feel free to ask for more information if required.
if you are able to drop .sh (shell script) and execut it on unix then you can do that with "rmdir yourfolder" command, if you folder has andything under then you will need to use "rm -r yourfolder", if files inside the folder have any dependicies you need to use "rm -rf yourfolder".
Just make sure that you will navigate to the correct folder where you are deleting things.
Br, Aljaž.
Use Command Task in Informatica Workflow to invoke syntax mentioned by #Aljaz

PSFTP rename file after transfer completed

I am transferring files through PSFTP to 3rd party server using Batch files. While transferring files, due to buffering issues, files are being broken/not transferred fully.
As a remedy, 3rd party requested us to name each file with '.new' before starting file transfer and remove '.new' once file is transferred fully/successfully.
Please let me know Batch script commands to implement above. Please let me know if you need additional info.
To rename a file, use mv command (or it's ren alias):
put c:\local\path\file /remote/path/file.new
mv /remote/path/file.new /remote/path/file
Though if you are transferring multiple files using a wildcard, this won't help you.
A relatively simple solution for multiple files is using a temporary upload folder. After the upload finishes, you can move all files at once to the target folder:
mput c:\local\path\* /temp/path
mv /temp/path/* /remote/path
For a similar discussion, see also SFTP file lock mechanism.
If you need to use the solution with extensions, you can use WinSCP, as it allows you to automatically use a temporary file name for upload. Though it uses .filepart, not .new extension.
put -resumesupport=on c:\local\path\* /remote/path/
See WinSCP article on Uploading to temporary file name for more details.
The article also shows (a way more complicated) solution using WinSCP .NET assembly that allows you to use even the .new extension.
If you choose to switch to WinSCP, there's a guide for converting psftp script to WinSCP.
(I'm the author of WinSCP)

Open ZIP/RAR automatically

do you know some kind of software, or way to script automatic dearchivation on Windows?
Ideally this thing should work like this:
Open file with this script/software
It will search files inside by mask (doc, pdf, jpg...) and if there is <2 of that files - script will open them, if > - unpack to C:/Temp or whatever
If there is archives inside - go to 1 and perform same thing to them
Any help would be appreciated:)
You should use the jolly character("*").
Try telling the script to open a file called *.doc, *pdf or *.jpg.

Converting a .exe to .pl in Perl?

I'm trying to get a Perl script (.pl) out of an executable (.exe) file. The .exe file was originally coded in Perl but the .pl file was not kept. Is there a quick way to do this? I'm using Strawberry Perl for windows.
Thanks
Rename .exe to .zip and check if files can be extracted
From the PAR FAQ:
How do I extract my script out of packed executable?
In other words, "I did a `pp foo.pl' and I lost foo.pl, how do I get it back?".
The answer is to just use unzip/winzip/winrar/whatever to decompress the executable, treating it like a normal Zip file. You may need to rename the executable into a .zip extension first.
pp relies on PAR to create the executable. PAR relies on Archive::Zip, so at some level the file contains zipped copies of the perl scripts used to create the executable.
Typically, these programs attach a loader to the front of a zip archive which unzips the files to a temporary directory and invokes the script indicated as the program's entry point.
I'd try two things:
root around in all the typical Temp directories (\Users\Username\AppData\Local\Temp for instance) for a directory containing your script and it's prerequsites.
try to uncompress the exe as a zip, possibly removing the loader from the start of he program first, using a byte editor.

Executing binary files with a shebang

I created a simple program that takes the path of a directory as an input, creates an archive of that directory (converting it into a single file), adds a shebang to that file (so that the contents of the file can be easily extracted), and writes the file to the base directory of the specified path.
The problem is that the file does not extract itself when I double click on it. Instead the operating system (I'm using Ubuntu 11.10) tries to open it with gedit. This obviously shows the shebang, random gibberish, and the contents of the archived files.
I made the file executable, first by using chmod +x; and when it still didn't work I tried chmod 777. However it still refuses to execute the file with the shebang when I double click on it. Perhaps this is because it's not a pure text file.
Interestingly when I try to execute the file directly from command line it reads the shebang and extracts the contents of the archive properly. So there's nothing wrong with my file format. I don't know much about what operating systems do when you double click on a file but I would sure like to understand.
It surely makes no sense to add a shebang to a file if you still need to manually execute it from the command line. One advantage could be that you don't need to specify the program to open it with but I believe that's hardly an advantage. Any help will be greatly appreciated.
Update 1:
The program that creates the archive is called opm. It can be installed via the node package manager using the following command:
npm install opm
After that you simply use opm to pack and unpack directories for you. For example if I have a directory called test in my home directory then I can open a terminal and execute the following command to pack it:
opm test
This will create an archive of the directory called test.pack in the home directory. The .pack file has the shebang #!/usr/bin/opm. Opening a file with the extension .pack with opm tells it that it's an archive and opm unpacks it in the same directory.
Note: Change the name of the test.pack file if you do not want it to overwrite your existing test directory.
I added the shebang to the .pack file so that it would extract itself when I opened it. However that doesn't seem to work. Nevertheless if I run one of the following command then it works:
./test.pack
You may check my source code and make any modifications to the program as you may wish to.
Update 2:
Alright I created the following .desktop file for opm and stored it in the $HOME/.local/share/applications/ directory:
[Desktop Entry]
Type=Application
Version=1.0
Encoding=UTF-8
Name=OPM
GenericName=Object Packer and Minifier
NoDisplay=true
Comment=JavaScript Package Manager
TryExec=opm
Exec=opm %f
Terminal=false
MimeType=application/opm
Now I was able to associate .pack files with opm by right clicking on a .pack file, going to the Properties window, the Open With tab, and setting opm.desktop as the default application. Now I am able to unpack a .pack file by simply opening it.
However I would like to know how to associate .pack files with the mime type application/opm. Currently the .pack files are associated with application/x-java-pack200. How do I do so? Is it better if I use a different extension (e.g. .opm)? By associating the packed archives with the mime type application/opm will the OS open them with opm by default without having to explicitly set a default application from Properties > Open With?
If there's already a MIME-type associated with .pack then you'll want to use a different extension (.opm) to associate with your MIME-type (application/opm). The way you automatically associate a program that opens files of a specific MIME-type is with xdg-mime .
Alternatively,
Edit ~/.local/share/applications/mimeapps.list and put your MIME/application combo under [Default Applications] like so:
[Default Applications]
application/opm=opm.desktop;
Place your opm.desktop file in ~/.local/share/applications/ folder. (You've already done this)

Resources