|
|
#1 |
|
Use a space in a "system" command
I'm trying to get into a directory from within a program, being written in C. I use the following command:
Code:
system("cd ~/Library/Application Support/ftblauncher");
__________________
Sudoku Solver: Step by Step Explanations Available for FREE on the app store. |
|
|
|
0
|
|
|
#2 |
|
Does this work?
Code:
system("cd \"~/Library/Application Support/ftblauncher\"");
|
|
|
|
0
|
|
|
#3 |
|
Unfortunately, no. When it runs I get:
sh: -c: line 0: unexpected EOF while looking for matching `"' sh: -c: line 1: syntax error: unexpected end of file
__________________
Sudoku Solver: Step by Step Explanations Available for FREE on the app store. |
|
|
|
0
|
|
|
#4 |
|
What happens if you make an array char by char? (Never tried it before, just a guess )
|
|
|
|
0
|
|
|
#5 |
|
Regardless of the space or not, I'm wondering what you hope to accomplish issuing a 'cd' command in system(). system() creates a child process, executes a shell, and executes that command within the shell. Then the process exits. So you changed directory within a process that then disappears.
|
|
|
|
0
|
|
|
#6 |
|
Try adding two backslashes before the space. The first one escapes the second one to make it a literal backslash, which is then passed to the cd command as an argument. However, mfram is correct. The command, as written, does essentially nothing.
|
|
|
|
0
|
|
|
#7 | |
|
Quote:
To the OP, if you want to "get into" a directory in a C program, use the chdir() or fchdir() C functions. You won't be able to use "~", either. There's no way that a system() command to 'cd' anywhere can possibly affect the process calling system(). There are no workarounds or tricks that can make it work. It's fundamental to all Posix/Unix systems. If that's not enough clues for a solution, then please explain exactly what you're trying to accomplish, which language you're writing in, and which OS version you need to target. The language is important, because there are other ways to do this in Objective-C, that don't necessarily require chdir or fchdir(), and there are options for resolving "~". And depending on what you're trying to accomplish, doing it in some other language (e.g. shell script) may be simpler and more effective than C. The OS version is important because it helps clarify what you're trying to accomplish. |
||
|
|
0
|
|
|
#8 |
|
Code:
system("cd ~/Library/Application\ Support/ftblauncher\");
__________________
2008 Aluminum MacBook, 2.4GHz IC2D, 8GB ram, 64bit EFI 10.6.8, 500GB momentus 7200.4 |
|
|
|
0
|
|
|
#9 |
|
|
0
|
|
|
#10 | |
|
Quote:
First step: Google for "bash". "bash" is the shell that will be executing the commands that "system" sends, so the first thing is you need to know what to send to bash. In this case, bash will try to execute the command Code:
cd ~/Library/Application Support/ftblauncher Next, get a good C book that explains escape characters in string literals. Try writing a program that prints Code:
"Hello, world!" Code:
"Hello, %fine% world!" |
||
|
|
0
|
|
|
#11 |
|
Hey guys, thanks for your responses. What I'm trying to do is make a program that goes into a directory and unzips a file there. In terminal I can use "cd" to go to a directory and then just use "unzip file.zip" to unzip the file. How would I do this in a C/Objective-C program?
__________________
Sudoku Solver: Step by Step Explanations Available for FREE on the app store. |
|
|
|
0
|
|
|
#12 |
|
Well, you probably shouldn't be doing whatever it is you're trying to do.
![]() But if you're hell-bent on calling unzip from within a C program, there are two ways you could do so. You could call unzip with the absolute path to the zip file as an argument, then the folder containing the zip file as an option using -d, like so: Code:
system("unzip /path/to/zip\\ file/myfile.zip -d /path/to/zip\\ file/");
Code:
system("cd /path/to/zip\\ file/ && unzip myfile.zip");
|
|
|
|
0
|
|
|
#13 |
|
Thanks, I'll try that out. The reason I need to do this is to help me with launching a mod pack in minecraft (for anyone who doesn't know, minecraft is a popular online game). I downloaded a cool mod pack for minecraft but there's a small bug in the program that causes it to crash on some macs (including mine). This is due to a file being named incorrectly. At the directory ~/Library/Application Support/ftblauncher/ there is a file name "locales.zip" which should be named "locale.zip" (no 's'). This causes the program to crash while looking for it. I can unzip the folder and change its name to "locale" manually, but unfortunately the name gets changed back whenever I exit minecraft. So I'd like to create a handy "helper program" that checks to see if "locales.zip" is there instead of "locale.zip". If it is I want the program to unzip "locales.zip" and change the folder name to "locale". Finally it should launch the java program. I've had no trouble checking to see if "locales.zip" is there, I'm just having trouble unzipping it.
__________________
Sudoku Solver: Step by Step Explanations Available for FREE on the app store. |
|
|
|
0
|
|
|
#14 |
|
Sounds like something that can be done by a shell script.
|
|
|
|
0
|
|
|
#15 |
|
Agreed, using C for this is absolutely overkill. If you do write that program, please send me the source code so I can submit it to The Daily WTF.
![]() What happens if you just symlink "locale" to "locales"? The command to do this, in case you don't know, is (from within the ftblauncher directory): Code:
ln -s locales locale |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 10:29 PM.









Linear Mode
