# Using "-cd" option of command line

**URL:** https://community.freefem.org/t/using-cd-option-of-command-line/483
**Category:** General Discussion
**Created:** [June 27, 2020, 3:10pm UTC](https://community.freefem.org/t/using-cd-option-of-command-line/483 "2020-06-27T15:10:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![arousta](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@arousta](https://community.freefem.org/u/arousta)
#### Post date: [June 27, 2020, 3:10pm UTC](https://community.freefem.org/t/using-cd-option-of-command-line/483/1 "2020-06-27T15:10:30Z")

</div>

I see there is a “-cd” option which FreeFem++ command takes.  
I think it means that FreeFem first cd into that directory and then runs. But I couldn’t figure out how to use it.

E.g. I have these files in /home/ar/code:  
main.edp, mesh.idp  
where main.edp includes mesh.idp

Now I want to run from say /home/ar/dir/. I tried:  
FreeFem++ -cd …/main.edp

But didn’t work. Also tried other variants, no success.  
What is the correct way to use -cd?

---

<div class="post-metadata">

### Author: ![arousta](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@arousta](https://community.freefem.org/u/arousta)
#### Post date: [July 10, 2020, 12:53pm UTC](https://community.freefem.org/t/using-cd-option-of-command-line/483/2 "2020-07-10T12:53:45Z")

</div>

Well looked in the source and I think there is a bug in the file `src/Graphics/getprog-unix.hpp` , function:

> int getprog(char\* fn,int argc, char \*\*argv)

It doesn’t handle the file name variable `fn` correctly. For example we call `FreeFem++ -cd ../t.edp` , then it cds to `..` but doesn’t chop-off the directory and keeps the files name as `../t.edp` which should be `t.edp`. So I added one line and it fixed the problem:

```
    if(i>0) {
        char *dir= new char [l+1];
        strcpy(dir,edpfilenamearg);
        strcyp(fn,edpfilenamearg+i+1); // Add this line to fix
        dir[i]=0;
        int err=0;
        if(verbosity>1)
            cout << " chdir '" << dir <<"'"<< endl;
        // FFCS: mingw64 API change
        err=chdir(dir);

```

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [July 10, 2020, 12:57pm UTC](https://community.freefem.org/t/using-cd-option-of-command-line/483/3 "2020-07-10T12:57:26Z")

</div>

Could you please submit a [pull request](https://github.com/FreeFem/FreeFem-sources/pulls)? Thanks in advance.

---

<div class="post-metadata">

### Author: ![arousta](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@arousta](https://community.freefem.org/u/arousta)
#### Post date: [July 11, 2020, 1:23pm UTC](https://community.freefem.org/t/using-cd-option-of-command-line/483/4 "2020-07-11T13:23:00Z")

</div>

Sure, done 🙂
