Hi all,
I have a proplem when embed shell into C code by Sytem() command.
There is my code:
char acCommand[512];
acCommand[0] = '\0';
sprintf(acCommand,"sed \'s/\<UDN\>\<\/UDN>/\<UDN\>%s\<\/UDN\>\/g\' %s > %s", initParam.UDN, "/tmp/web/dmr.xml", "/tmp/web/dmr.xml.tmp");
printf("[%s]", acCommand);
system(acCommand);

and below is output after compiling:
sed 's/<UDN></UDN>/<UDN>uuid:b346ee95-93b3-4922-a132-cf72762b9318</UDN>/g' /tmp/web/dmr.xml > /tmp/web/dmr.xml.tmp]
sed: bad option in substitution expression
I thinks the bad option is <\/UDN\>
I have tried to do something but it still doesn't work, same as above problem.

Could you please help me to solve this problem.
Thanks.

Use ";" instead of "/" as the sed separators.
instead of

s/<UDN></UDN>/<UDN>uuid:b346ee95-93b3-4922-a132-cf72762b9318</UDN>/g

use

s;<UDN></UDN>;<UDN>uuid:b346ee95-93b3-4922-a132-cf72762b9318</UDN>;g

as that "/" in "</UDN>" is garbling your sed command.

I am going to try it now, thanks

great, many thank masijade.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.