Running console commands to convert with ImageMagick from within Unity 3d - windows

Folks!
So, I'm attempting to convert a PDF to a .png, as the title implies. I'm using the software package ImageMagick. I want to use this package to convert pdfs to pngs on-the-fly from a Unity 3d project -- so that the application can display the PDFs as .png textures in-game when it needs, but still preserves them as PDFs for smaller file sizes. I'm not quite sure what I've done wrong, here -- but when I run it in Unity, all I get is an open cmd prompt without my command in it. Is there something obvious that I'm missing, here? Here's the code:
using UnityEngine;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Security.Policy;
public class CommandLineTest : MonoBehaviour {
// Use this for initialization
void Start () {
string convertedDirName = "ConvertedPDFs";
string currDir = System.Environment.CurrentDirectory;
System.IO.Directory.CreateDirectory(currDir + #"\" + convertedDirName);
string strCmdText;
strCmdText= #"/c " + currDir + #"\ImageMagick\convert.exe " + currDir + #"\PDFs\Appointment.pdf " + currDir + #"\" + convertedDirName + #"\" + "Appointment.png";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);
//ImageMagick
print(strCmdText);
}
}
When the print statement at the end runs, it prints the following string: c/ convert /c F:\Documents and Settings\Administrator\Desktop\ImageMagickTest\ImageMagick\convert.exe F:\Documents and Settings\Administrator\Desktop\ImageMagickTest\PDFs\Appointment.pdf F:\Documents and Settings\Administrator\Desktop\ImageMagickTest\ConvertedPDFs\Appointment.png
Does anything appear obviously wrong, to you? I should mention that ImageMagick's convert application is not actually "installed" on my system -- I'm just using the "portable" version and have thrown it in my project folder. So I was hoping that the "convert" command line would still work. Does this mean that I can't access it with a dos prompt? If I can't, then how do I pass an image to the "convert" program in imagemagick using, provided I know that it's going to be in my project's folder?
EDIT: Some people have suggested that I access convert.exe instead of cmd.exe, and to attempt to just feed the image paths to it that way. So here is the second way I'm trying it:
strCmdText= currDir + #"\PDFs\Appointment.pdf" + " " + currDir + #"\" + convertedDirName + #"\" + "Appointment.png";
System.Diagnostics.Process.Start(currDir + #"\ImageMagick\convert.exe",strCmdText);

Try using some other commands (like dir) to figure out where you are in the filesystem and what is going wrong.
Also remember that if you are using the portable version and it is not in your path, you will have to execute it from the same directory as it is in.

Related

E764: option 'omnifunc' is not set. Just storing a file in path

Im trying to set path .bash_profile
here is what i write: export PATH=&PATH:/usr/local/ant/bin
To exit and save i use Control + X and Control + O but get this error every time: E764: option 'omnifunc' is not set.
Purpose is to install ant migration tool
Im using mac os
You should put :
export PATH=$PATH:/usr/local/ant/bin
Then
Esc:wq
Control + X and Control + O, is it for nano editor ?

Using Windows Command Line with Python Subprocess Module

So basically I've got the worst situation possible on Windows... A path with spaces on a drive other than C:/
I'm trying to run the following:
print(subprocess.check_call("cd d: && d: && " + '"' + dir_name + '"', shell=True))
Where dir_name is the name of the directory plus the name of the executable file. The way I get dir_name is as follows:
dir_path = os.path.dirname(os.path.realpath(__file__))
dir_name = (dir_path.replace("\\","/") + "/bowtie2-2.3.4-mingw-x86_64/bowtie2-build").replace(" ", "\\ ")
I've also tried a few different variants of dir_name:
dir_path + "/bowtie2-2.3.4-mingw-x86_64/bowtie2-build"
dir_path.replace("\\","/")+"/bowtie2-2.3.4-mingw-x86_64/bowtie2-build"
I've tried it with and without quotes surrounding the whole thing, I've tried it with and without the shell option, I've tried it in cmd.exe and basically every time I get something along the lines of:
The system cannot find the path specified.
The full path is essentially:
D:/My Documents/2018 Documents/Class Name/Assignment Name/Subfile/ProgramName
With the variants I've tried being:
D://My Documents//2018 Documents//Class Name//Assignment Name//Subfile//ProgramName
D:/My\ Documents/2018\ Documents/Class\ Name/Assignment\ Name/Subfile/ProgramName
D://My\ Documents//2018\ Documents//Class\ Name/Assignment\ Name//Subfile//ProgramName
"D:/My Documents/2018 Documents/Class Name/Assignment Name/Subfile/ProgramName"
"D:/My\ Documents/2018\ Documents/Class\ Name/Assignment\ Name/Subfile/ProgramName"
"D://My\ Documents//2018\ Documents//Class\ Name//Assignment\ Name//Subfile//ProgramName"
I'm up for anything at this point, thank you so much in advance!
EDIT #1:
Based on comments, I should add that I'm trying to run bowtie2-build which is an extensionless program in the Bowtie package. It takes two command-line arguments, an input file and an output file name.

Sublime Text snippets in Ace Editor

Hey i know that we can use Sublime Texts .tmLanguage syntax in Ace Editor with the tools that comes with ace. Is it possible to even use Sublime Texts .sublime-snippet snippets in Ace Editor.
In sublime's folder You can find snippets at Packages/HTML/HTML.sublime-completions.
And then there is ace/lib/ace/snippets
folder in Ace Editor.
I haven't done it myself, but I am pretty sure that you can combine files in those folders. Have an experiment. :)
Good luck!
there is no automatic converter, but adding one is relatively straightforward,
parse xml of sublime snippet file and either keep it as json or as ace/snipmate snippets file
var sublimeSnippet = plist.parse(xml)
var aceSnippet = ""
+ "snippet " + sublimeSnippet.tabTrigger
+ "description " + sublimeSnippet.description
+ "scope " + sublimeSnippet.scope.replace(/source\./g, "")
+ "\t" + sublimeSnippet.content.replace(/\r?\n/g, "\n\t")
+ "\n"

How to copy/cut a file (not the contents) to the clipboard in Windows on the command line?

Is there a way to copy (or cut) a file to the Windows clipboard from the command line?
In particular with a batch script. I know how to copy the contents to the clipboard (type file | clip), but this is not the case. I want to have the whole file as I would press Ctrl + C in Windows Explorer.
OK, it seems the easiest way was to create a small C# tool that takes arguments and stores them in the clipboard:
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace File2Clip
{
public class App
{
[STAThread]
static void Main(string[] args)
{
List<string> list = new List<string>();
string line;
while(!string.IsNullOrEmpty(line = Console.ReadLine())) list.Add(line);
foreach (string s in args) list.Add(s);
StringCollection paths = new StringCollection();
foreach (string s in list) {
Console.Write(s);
paths.Add(
System.IO.Path.IsPathRooted(s) ?
s :
System.IO.Directory.GetCurrentDirectory() +
#"\" + s);
}
Clipboard.SetFileDropList(paths);
}
}
}
2017 edit: Here's a github repo with both source and binary.
This would place the contents of the file into the clipboard (accomplished by clip.exe).
type \path\to\file|clip
To get the actual file, you'll probably have to resort to some other programming language, like VBScript or PowerShell to access Windows API's. I'm not entirely certain what Explorer puts into the clipboard when you CTRL+C a file. I suspect it uses the notification system to do something more intelligent than put the path to the file there. Depending on the context of the CTRL+V, you'll get something (Explorer, Word) or nothing (Notepad).
I've forever wanted this to use in Emacs, so, inspired by this question, an answer here, and a goodly amount of NIH syndrome, I've written a C version available at
https://github.com/roryyorke/picellif
picellif also handles wildcards (it's not clear to me if rostok's C# version does or not).
copy and move are (some of) the batch commands that copy/paste and cut/paste files, respectively. We don't use the terms paste or cut when dealing with files but if I understand you there is a need to copy a file to another location and to move files to another location.
You can try Swiss File Knife (SFK):
sfk toclip
Copy stdin to clipboard as plain text.
type test.txt | sfk toclip
Copies the content of ASCII file test.txt into the clipboard.
sfk list | sfk toclip
Copies a file listing of the current dir into the clipboard.
sfk fromclip [-wait] [-clear]
Dump plain text content from the clipboard to the terminal.
-wait : block until plain text is available.
-clear: empty the clipboard after reading it.
Example: turn backslashes into forward slashes. Imagine you have the following text open within Notepad:
foo/bar/systems/alpha1.cpp
foo/bar/systems/alpha2.cpp
foo/bar/systems/beta1.cpp
And for some reason you need the first line in a format like this:
foo\bar\systems\alpha1.cpp
Then you may do it this way:
Mark the first line using SHIFT + CURSOR keys.
Press Ctrl + C or Ctrl + Insert to copy it into clipboard
On the Windows command line, run this command (for example, from a batch file):
sfk fromclip +filter -rep x/x\x +toclip
Back in the editor, press Ctrl + V or Shift + Insert, pasting the result from the clipboard.
As you see, the line changed into "foo\bar\systems\alpha1.cpp".
You can use Command Line Copy and Paste Files utilities on Sid's Bytestream.

importing multiple images matlab

I have a set of 100 jpg images named consecutively and I want to add them up to get a single image. I have seen the answer from here, but it does not run with me, what happened?
Here is the code:
im = imread('C:\Documents and Settings\1026175117_1.jpg');
for i = 2:10
im = imadd(im,imread(sprintf('C:\Documents and Settings\1026175117_%d.jpg',i)));
end
im = im/1000;
imshow(im,[]);
Here's the error message:
Error using ==> imread
Can't open file "C:" for reading;
you may not have read permission.
Backslash is a special character for sprintf() and needs to be escaped. Either use "\\" instead of "\" or try constructing your file paths another way. fullfile() is a good way to do it, so you only have to use sprintf for the file name part. Also see help sprintf.

Resources