concatenate two files

13 views
Skip to first unread message

Bryan Murdock

unread,
Jan 28, 2015, 5:15:49 PM1/28/15
to fabrica...@googlegroups.com
I'm trying this:

run('cat', 'file1', 'file2', '>', 'file3')

but I get this error:

cat: >: No such file or directory

Is there a way to do this with the fabricate.run function, or do I
need to put my cat command in a file and call that with the run
function?

Bryan

Lex Trotman

unread,
Jan 28, 2015, 5:57:59 PM1/28/15
to fabrica...@googlegroups.com
Use the parameter `shell=True` in the run() call I think

Cheers
Lex
> --
> You received this message because you are subscribed to the Google Groups "fabricate users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fabricate-use...@googlegroups.com.
> To post to this group, send email to fabrica...@googlegroups.com.
> Visit this group at http://groups.google.com/group/fabricate-users.
> For more options, visit https://groups.google.com/d/optout.

Bryan Murdock

unread,
Jan 28, 2015, 6:19:00 PM1/28/15
to fabrica...@googlegroups.com
If I do this:

run('cat file1 file2 > file3', shell=True)

I get this:

"cat file1 file2 > file3"

strace: cat file1 file2 > file3: command not found

fabricate: 'strace' exited with status 1

If I do this:

run('cat', 'file1', 'file2', '>', 'file3', shell=True)

Then it works.

Thanks!

Bryan

Lex Trotman

unread,
Jan 28, 2015, 6:29:09 PM1/28/15
to fabrica...@googlegroups.com
On 29 January 2015 at 09:18, Bryan Murdock <bmur...@gmail.com> wrote:
> If I do this:
>
> run('cat file1 file2 > file3', shell=True)
>
> I get this:
>
> "cat file1 file2 > file3"
>
> strace: cat file1 file2 > file3: command not found
>
> fabricate: 'strace' exited with status 1
>
> If I do this:
>
> run('cat', 'file1', 'file2', '>', 'file3', shell=True)

Well, thats how you should run all commands, with each argument a
separate parameter to run, see https://code.google.com/p/fabricate/
example. That way there are no problems with spaces in filenames and
such.

Cheers
Lex

Bryan Murdock

unread,
Jan 28, 2015, 7:08:12 PM1/28/15
to fabrica...@googlegroups.com
On Wed, Jan 28, 2015 at 4:29 PM, Lex Trotman <ele...@gmail.com> wrote:
> On 29 January 2015 at 09:18, Bryan Murdock <bmur...@gmail.com> wrote:
>> If I do this:
>>
>> run('cat file1 file2 > file3', shell=True)
>>
>> I get this:
>>
>> "cat file1 file2 > file3"
>>
>> strace: cat file1 file2 > file3: command not found
>>
>> fabricate: 'strace' exited with status 1
>>
>> If I do this:
>>
>> run('cat', 'file1', 'file2', '>', 'file3', shell=True)
>
> Well, thats how you should run all commands, with each argument a
> separate parameter to run, see https://code.google.com/p/fabricate/
> example. That way there are no problems with spaces in filenames and
> such.

Interesting, when I run the cat command as above it doesn't track
file3 as an output in the .deps file. When I make a little script
that does the cat operation and call that script with the run command
it does track file3 as an output. I guess I need to stick with the
script solution after all.

Bryan

Lex Trotman

unread,
Jan 28, 2015, 8:12:28 PM1/28/15
to fabrica...@googlegroups.com
Ahh, yeah, the shell is applied at the top level, above strace, so
strace doesn't see the writes to file3. You could avoid a script by
running shell explicitly: run('/bin/sh', '-c', 'cat f1 f2 >f3')

Cheers
Lex

Bryan Murdock

unread,
Jan 28, 2015, 9:07:10 PM1/28/15
to fabrica...@googlegroups.com
On Wed, Jan 28, 2015 at 6:12 PM, Lex Trotman <ele...@gmail.com> wrote:
> On 29 January 2015 at 10:08, Bryan Murdock <bmur...@gmail.com> wrote:
>> On Wed, Jan 28, 2015 at 4:29 PM, Lex Trotman <ele...@gmail.com> wrote:
>>> On 29 January 2015 at 09:18, Bryan Murdock <bmur...@gmail.com> wrote:
>>>> If I do this:
>>>>
>>>> run('cat file1 file2 > file3', shell=True)
>>>>
>>>> I get this:
>>>>
>>>> "cat file1 file2 > file3"
>>>>
>>>> strace: cat file1 file2 > file3: command not found
>>>>
>>>> fabricate: 'strace' exited with status 1
>>>>
>>>> If I do this:
>>>>
>>>> run('cat', 'file1', 'file2', '>', 'file3', shell=True)
>>>
>>> Well, thats how you should run all commands, with each argument a
>>> separate parameter to run, see https://code.google.com/p/fabricate/
>>> example. That way there are no problems with spaces in filenames and
>>> such.
>>
>> Interesting, when I run the cat command as above it doesn't track
>> file3 as an output in the .deps file. When I make a little script
>> that does the cat operation and call that script with the run command
>> it does track file3 as an output. I guess I need to stick with the
>> script solution after all.
>
> Ahh, yeah, the shell is applied at the top level, above strace, so
> strace doesn't see the writes to file3. You could avoid a script by
> running shell explicitly: run('/bin/sh', '-c', 'cat f1 f2 >f3')

Interesting. I haven't tried that with the cat command, but I have
another command that is essentially:

codegentool ../input_file -a -b -c ../config_file -o output_file

and the only input file fabricate lists in the .deps file is "."

I tried wrapping it with /bin/sh like you mention above and that
didn't fix anything. Is it the relative paths that are tricking
fabricate's input dependency detection? It's been a few years since
I've done anything with fabricate and as I type that I'm vaguely
remembering that that might be the case.

Bryan

Bryan Murdock

unread,
Jan 28, 2015, 9:21:48 PM1/28/15
to fabrica...@googlegroups.com
Or does this have something to do with build_dir? If I don't pass
build_dir='.' to main it does a:

cd ..

before running my command, which then fails because the relative path
is no longer valid. That's why I pass in build_dir='.' to main.

Bryan

Lex Trotman

unread,
Jan 28, 2015, 9:53:05 PM1/28/15
to fabrica...@googlegroups.com
IIRC it only looks for deps in some "relevant" directories, perhaps
the ../paths are going outside those. See the -d option.

Bryan Murdock

unread,
Jan 29, 2015, 12:06:56 PM1/29/15
to fabrica...@googlegroups.com
On Wed, Jan 28, 2015 at 7:53 PM, Lex Trotman <ele...@gmail.com> wrote:
> IIRC it only looks for deps in some "relevant" directories, perhaps
> the ../paths are going outside those. See the -d option.

Thank you! That fixed it.

Bryan
Reply all
Reply to author
Forward
0 new messages