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

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

Related

AHK Run command with directory path containing space

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"

Folder name with space issue

How do I handle a folder name containing spaces in Perl? For example C:\Sample Picture\Data.
I wrote this
use File::Glob ':glob';
$indir = "C:\\Sample Picture\\Data\\";
#flist = bsd_glob( $indir.'*');
This is throwing an error
The syntax of the command is incorrect.
The error message The syntax of the command is incorrect comes from the Windows command line, not from Perl
The issue is not to do with File::Glob, but with whatever you are doing with the contents of #flist. It's my guess that you're using backticks or system to rename one or more of the files or directories. This will fail if you use paths that contain spaces without enclosing the complete path in double quotes
If you need any more help then you must show the relevant part of your code

tcl exec to open a program with agruments

I want to open a text file in notepad++ in a particular line number. If I do this in cmdline the command should be:
start notepad++ "F:\Path\test.txt" -n100
And it is working fine from command line. Now I have to do this from tcl. But I can't make this command work with exec. When I try to execute this:
exec "start notepad++ \"F:\Path\test.txt\" -n100"
I am getting this error:
couldn't execute "start notepad++ "F:\Path\test.txt" -n100": no such file or directory.
What am I missing. Please guide.
Similar to this question:
exec {*}[auto_execok start] notepad++ F:/Path/test.txt -n10
First, you need to supply each argument of the command as separate values, instead of a single string/list. Next, to mimic the start command, you would need to use {*}[auto_execok start].
I also used forward slashes instead of backslashes, since you would get a first level substitution and get F:Path est.txt.
EDIT: It escaped me that you could keep the backslashes if you used braces to prevent substitution:
exec {*}[auto_execok start] notepad++ {F:\Path\test.txt} -n10
You can simply surround the entire exec statement in curly braces. Like this:
catch {exec start notepad++.exe f:\Path\test.txt -n10}
I haven't found a perfect solution to this yet. All my execs seem to be different from each other. On windows there are various issues.
Preserving double quotes around filename (or other) arguments.
e.g. in tasklist /fi "pid eq 2060" /nh the quotes are required.
Preserving spaces in filename arguments.
Preserving backslash characters in filename arguments.
[Internally, Windows doesn't care whether pathnames have / or \, but some programs will parse the filename arguments and expect the backslash character].
The following will handle the backslashes and preserve spaces, but will not handle double-quoted arguments. This method is easy to use. You can build up the command line using list and lappend.
set cmd [list notepad]
set fn "C:\\test 1.txt"
lappend cmd $fn
exec {*}$cmd
Using a string variable rather than a list allows preservation of quoted arguments:
set cmd [auto_execok start]
append cmd " notepad"
append cmd " \"C:\\test 1.txt\""
exec {*}$cmd
Note that if you need to supply the full path to the command to be executed, it often needs to be quoted also due to spaces in the pathname:
set cmd "\"C:\\Program Files\\mystuff\\my stuff.exe\" "

What's wrong with this Bitvise Tunnelier SFTP command?

I'm trying to put together an SFTP command to be run through Powershell. The executable I have access to is SFTPC.exe (Bitvise Tunnelier)
The command I'm trying is
sftpc.exe user#ftp.domain.com -pw=password -unat=y -cmd="ls \"somefile.txt\""
According to the documentation at https://www.bitvise.com/files/sftpc-v4.14-usage.txt this should log in and run the command ls "somefile.txt" (quotes are escaped within the command parameter)
What actually happens is that I get another line for input, as if there's an unclosed quote.
I've tried adding an extra quote to the end
sftpc.exe user#ftp.domain.com -pw=password -unat=y -cmd="ls \"somefile.txt\"""
This connects and logs in, but the colland it tries to run is ls \somefile.txt"
Note the trailing quote and the leading slash.
So it looks like I'm missing something in the quote escaping, but I can't see what I might be doing wrong. I've also tried replacing double quotes with single in a couple of different places, experiments that usually end in a syntax error.
The escape character in powershell is not a backslash, it's the backtick.
Does the below work?
sftpc.exe user#ftp.domain.com -pw=password -unat=y -cmd="ls `"somefile.txt`""

How to empty a file in fish?

In bash shell scripting, I would typically run :> file to empty a file.
Now using fish, things are slightly different and the above command doesn't work.
What is fish equivalent?
Although it's not as short as :, true is a command that will work everywhere and produces no output:
true > file
Probably the easiest way that will be work in both Fish and Bash is to do echo "" > file
EDIT: Commenter was absolutely right echo "" > file produces a file with a newline, the correct command I was thinking of to create an empty file is cat /dev/null > file.
There is, and always was the magic method called touch which set change time to actual or create non-existent file. For compatiblity I suggest you to use this way in all scripts that you write (even if you write bash code).